id
int64
0
45.1k
file_name
stringlengths
4
68
file_path
stringlengths
14
193
content
stringlengths
32
9.62M
size
int64
32
9.62M
language
stringclasses
1 value
extension
stringclasses
6 values
total_lines
int64
1
136k
avg_line_length
float64
3
903k
max_line_length
int64
3
4.51M
alphanum_fraction
float64
0
1
repo_name
stringclasses
779 values
repo_stars
int64
0
882
repo_forks
int64
0
108
repo_open_issues
int64
0
90
repo_license
stringclasses
8 values
repo_extraction_date
stringclasses
146 values
sha
stringlengths
64
64
__index_level_0__
int64
0
45.1k
exdup_ids_cmlisp_stkv2
sequencelengths
1
47
33,157
histogram.lsp
rwoldford_Quail/source/views/d-views/histogram.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; histogram.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(break-points-of compute-break-points set-nbins set-break-points histogram-view histogram-bar bar-heights-of ))) ;;;---------------------------------------------------------------------------------- #| (defclass histogram-bar (bar) () (:documentation "A kind of bar which handles highlighting as appropriate for ~ a histogram bar.")) (defmethod highlight-view ((self histogram-bar) &key viewport ) "Highlight a proportion of each color-fill combintation ~ by examining drawing styles. " (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((op (highlight-operation self)) (axis (orientation-of self)) (x-wid (- r l)) (y-wid (- tp b)) (w (window-of vp)) (highlight-proportion 0)) (setf highlight-proportion (or (loop with styles = (style-proportions self '(:highlight?)) for (style) in (first styles) for prop in (second styles) thereis (and style prop)) 0) ) (unless (zerop highlight-proportion) (if (eql axis :horizontal) (setq y-wid (round (* highlight-proportion (+ 1 y-wid)))) (setq x-wid (round (* highlight-proportion (+ 1 x-wid))))) (wb:canvas-highlight-rectangle w l (min r (+ l x-wid)) b (min tp (+ b y-wid)) :color *default-highlight-color* :operation op) ))))) (defmethod draw-view ((self histogram-bar) &key viewport ) "Color and fill self in proportion to the colors/fill of the drawing-style." (if (collect-styles-p self) (call-next-method) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((axis (orientation-of self)) (x-wid (- r l)) (y-wid (- tp b)) (w (window-of vp))) (cond ((zerop x-wid) (wb:canvas-draw-line w l b l tp :color (draw-style self :color))) ((zerop y-wid) (wb:canvas-draw-line w l b r b :color (draw-style self :color))) (t (loop with l1 and b1 and tp1 and r1 and last-fill = nil with styles = (style-proportions self '(:highlight? :fill? :color )) with nstyles = (length (first styles)) for (hi fill col) in (first styles) for (next-fill) in (append (cdr (first styles)) (list nil nil nil)) for prop in (second styles) for i upfrom 1 do (if (eql axis :horizontal) (setq y-wid (round (* prop (+ 1 (height-of vp))))) (setq x-wid (round (* prop (+ 1 (width-of vp)))))) (setq b1 b tp1 (min tp (+ b y-wid)) l1 l r1 (min r (+ l x-wid))) (cond (fill (wb:canvas-draw-filled-rectangle w l1 r1 b1 tp1 :color col)) ((eql axis :horizontal) (wb:canvas-draw-line w l1 b1 l1 (1- tp1) :color col) (wb:canvas-draw-line w r1 b1 r1 (1- tp1) :color col) (unless last-fill (wb:canvas-draw-line w l1 b1 r1 b1 :color col)) (unless next-fill (if (= nstyles i) (wb:canvas-draw-line w l1 tp1 r1 tp1 :color col) (wb:canvas-draw-line w l1 (1- tp1) r1 (1- tp1) :color col)))) (t (wb:canvas-draw-line w l1 b1 (1- r1) b1 :color col) (wb:canvas-draw-line w l1 tp1 (1- r1) tp1 :color col) (unless last-fill (wb:canvas-draw-line w l1 b1 l1 tp1 :color col)) (unless next-fill (if (= nstyles i) (wb:canvas-draw-line w r1 b1 r1 tp1 :color col) (wb:canvas-draw-line w (1- r1) b1 (1- r1) tp1 :color col)))) ) (if (eql axis :horizontal) (incf b y-wid) (incf l x-wid)) (setq last-fill fill) )) )))))) (defmethod highlight-view ((self histogram-bar) &key viewport ) "Highlight a proportion of each color-fill combintation ~ by examining drawing styles. " (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((op (highlight-operation self)) (axis (orientation-of self)) (x-wid (- r l)) (y-wid (- tp b)) (w (window-of vp)) (highlight-proportion 0)) (setf highlight-proportion (loop with styles = (if (collect-styles-p self) (style-proportions self '(:fill? :color :highlight?)) (style-proportions-in-order self '(:fill? :color :highlight?))) for style in (first styles) for prop in (second styles) sum (if (third style) prop 0)) ) (if (eql axis :horizontal) (setq y-wid (round (* highlight-proportion (+ 1 (height-of vp))))) (setq x-wid (round (* highlight-proportion (+ 1 (width-of vp)))))) (wb:canvas-highlight-rectangle w l (min r (+ l x-wid)) b (min tp (+ b y-wid)) :color *default-highlight-color* :operation op) )))) |# (defclass histogram-view (boxed-subview-mixin styles-cache 1d-view compound-view) ((middle-menu :allocation :class :initform nil) (filled? :allocation :class :initform nil :accessor filled-p) (style-keys :initform '(:size :fill? :box-color :color) :allocation :class) (break-points :initform nil :initarg :break-points :accessor break-points-of) (scale :initform :frequency :initarg :histogram-scale :accessor histogram-scale-of :documentation "Possibilities are :frequency :relative-frequency or :density")) (:default-initargs :justification :bottom :fill? *default-bar-fill?* :orientation :horizontal :box? nil :color *default-bar-color*)) (defgeneric set-nbins (histogram-view &key nbins draw?) (:documentation "Set number of bins.~ If nbins is nil, the user is prompted.")) (defgeneric set-break-points (histogram-view &key break-points draw?) (:documentation "Set break-points.~ If break-points is nil, the user is prompted.")) (defgeneric set-histogram-scale (histogram-view &key scale draw?) (:documentation "Sets histogram scale to scale")) (defgeneric bar-heights-of (bars) (:documentation "Returns heights of bars")) (defgeneric compute-bar-heights (histogram-view scale) (:documentation "Computes and returns the bar heights using scale~ :frequency :relative-frequency or :density")) (defgeneric compute-break-points ( histogram-view &optional nbins ) (:documentation "Returns a list of break points used to form the histogram bins.~ If nbins is provided, there will be nbins+1 break points.")) ;;;---------------------------------------------------------------------------------- (defun default-nbins (n) (if (zerop n) 0 (max 2 (truncate (+ 1 (log n 2)))))) (defun compute-bins(min max nbins &optional (fudge 0)) (if (= min max) (incf max 1)) (let ((tic-info (scale-axis min max (1+ nbins)) )) (when (= (tic-max tic-info) max) (setq fudge (* fudge (- max min))) (setq tic-info (scale-axis min (+ max fudge) (1+ nbins)))) (loop with wid = (tic-inc tic-info) for i from 0 to nbins collect (+ (tic-min tic-info) (* i wid))))) (defmethod compute-break-points ((self histogram-view) &optional nbins ) (unless (break-points-of self) (let* ((coords (active-members self (plot-coords-of self))) max min) (if (null coords) (setf (break-points-of self) nil) (progn (loop for c in coords maximize c into amax minimize c into amin finally (setq min amin max amax)) (unless nbins (setf nbins (default-nbins (length ( active-members self (cases-of self)))))) (setf (break-points-of self) (compute-bins min max nbins 0.01)))))) (break-points-of self)) (defun equispaced-list-p (l &optional fudge) "Tests if list elements are equispaced" (if l (if fudge (loop with diff = (- (second l) (first l)) with d2 = (* diff (1+ fudge)) with d1 = (* diff (1- fudge)) for b1 in (cdr l) for b2 in (cddr l) always (<= d1 (- b2 b1) d2)) (loop with diff = (- (second l) (first l)) for b1 in (cdr l) for b2 in (cddr l) always (= (- b2 b1) diff))))) (defun which-interval-fn (l) "Returns a function which gives the~ index 0..length(l) -2 of the interval~ containing its argument" (let ((n (- (length l) 1))) (if (equispaced-list-p l) (let* ((left (first l)) (right (first (last l))) (fac (/ n (- right left)))) #'(lambda (c) (let ((bin (floor (* (- c left) fac)))) (if (and ( >= bin 0) (< bin n)) bin)))) #'(lambda (c) (let ((p (position c l :test #'<))) (if (and p (> p 0)) (- p 1))))))) (defmethod construct-sub-views ((self histogram-view) &key nbins break-points bars fill? color) (if break-points (setf (break-points-of self) break-points)) (let* ((bp (compute-break-points self nbins )) (orientation (orientation-of self)) (style-arglist (append bars (list :color color :fill? fill? ))) sub-styles sub-vos) (setq bars (subview-arg-list bars 'bar)) (when bp (multiple-value-setq ( sub-vos sub-styles) (group-and-sort-viewed-objs self (which-interval-fn bp) (- (length bp) 1) (get-viewed-obj-styles self :fill? (getf style-arglist :fill?) :color (getf style-arglist :color)))) (loop while (null (first sub-vos)) do (setf sub-vos (cdr sub-vos)) (setf sub-styles (cdr sub-styles)) (setf (break-points-of self) (cdr (break-points-of self) ))) (loop while (null (car (last sub-vos))) do (setf sub-vos (butlast sub-vos)) (setf sub-styles (butlast sub-styles)) (setf (break-points-of self) (butlast (break-points-of self)))) (setf (subviews-of self) (loop for vos in sub-vos for vo-style in sub-styles collect (apply #'view :data vos :check-style? t :viewed-elements vos :orientation orientation :drawing-style vo-style bars))) ) )) (defmethod set-nbins ((self histogram-view) &key nbins (draw? t)) (if (null nbins) (setq nbins (wb:prompt-user :result-type 'number :read-type :eval :prompt-string "Enter a positive integer"))) (with-constrained-extents self draw? (let () (new-sub-views self :nbins nbins) (init-position-subviews self) (set-bounding-region self )))) (defmethod set-break-points ((self histogram-view) &key break-points (draw? t)) (if (null break-points) (setq break-points (wb:prompt-user :result-type 'list :read-type :read :prompt-string "Enter a list of break points"))) (with-constrained-extents self draw? (let () (new-sub-views self :break-points break-points) (init-position-subviews self) (set-bounding-region self )))) (defmethod set-histogram-scale ((self histogram-view) &key scale (draw? t)) (setf (histogram-scale-of self) scale) (with-constrained-extents self draw? (let () (init-position-subviews self) (set-bounding-region self ))) (update-text-links self)) (defmethod new-sub-views :before ((self histogram-view) &key) (setf (break-points-of self) nil)) (defmethod bar-heights-of ((self histogram-view)) (let ((b (break-points-of self))) (if (and b (not (equispaced-list-p b .0001))) (setf (histogram-scale-of self) :density))) (compute-bar-heights self (histogram-scale-of self))) (defmethod compute-bar-heights ((self histogram-view) (scale t)) (loop for bar in (subviews-of self) when (typep bar 'bar) collect (bar-count bar))) (defmethod compute-bar-heights ((self histogram-view) (scale (eql :relative-frequency))) (let* ((heights (compute-bar-heights self :frequency)) (scale (loop for h in heights sum h))) (mapcar #'(lambda(x) (/ x scale)) heights))) (defmethod compute-bar-heights ((self histogram-view) (scale (eql :density))) (let* ((heights (compute-bar-heights self :frequency)) (break-points (break-points-of self)) (scale (loop for h in heights sum h)) ) (unless (zerop scale) (setq scale (/ 1 scale))) (loop for h in heights for b1 in break-points for b2 in (cdr break-points) collect (/ (* scale h) (- b2 b1))))) (defmethod smallest-bounding-region ((self histogram-view) ) (let ((br (call-next-method self)) hgt) (when (and (bar-heights-of self) (cases-of self)) (setq hgt (apply #'max (bar-heights-of self))) (multiple-value-bind (l r b tp) (bounds-of br ) (setf (bounds-of br) (if (eq (orientation-of self) :vertical) (list 0.0 hgt b tp) (list l r 0.0 hgt) )))) br)) (defmethod set-bounding-region :after ((self histogram-view) &key (pretty? t) ignore-x? ignore-y? &allow-other-keys) (let ((dir (axis-of-orientation self))) (if (and pretty? (break-points-of self) (not (or (and ignore-x? (eq dir :x)) (and ignore-y? (eq dir :y))) )) (let ((min-pt (first (break-points-of self))) (max-pt (first (last (break-points-of self))))) (expand-extent self (list min-pt max-pt)))))) (defmethod init-position-subviews ((self histogram-view) &key) (loop with reg for bar in (subviews-of self) for b1 in (break-points-of self) for b2 in (cdr (break-points-of self)) for hgt in (bar-heights-of self) do (setq reg (if (eq (orientation-of self) :vertical) (make-region 0.0 hgt b1 b2 ) (make-region b1 b2 0.0 hgt) )) (place-subview self bar reg)) ) (defmethod allowed-subview-movement ((self histogram-view) subview) ;; histogram bars may not be moved (declare (ignore subview)) :none) (defmethod style-menu-items ((self histogram-view)) `(( "Color" nil "" :sub-items ,(color-menu-items)) ("Invisible?" (set-drawing-style :invisible? :toggle :highlit? *selected-subviews-only* )) ("Fill?" (set-drawing-style :fill? :toggle :highlit? *selected-subviews-only*)) )) (defmethod get-menu-items ((self histogram-view) (slot-name (eql 'middle-menu))) `(("# Bins" (set-nbins)) ("BreakPoints" (set-break-points)) ("Scale" nil "" :sub-items (("Frequency" (set-histogram-scale :scale :frequency)) ("RelFrequency" (set-histogram-scale :scale :relative-frequency)) ("Density" (set-histogram-scale :scale :density)))))) (defmethod toggle-fill ((self histogram-view) &key keys ) (setf (filled-p self) (not (filled-p self))) (apply #'set-drawing-style self :fill? (filled-p self) keys)) (defmethod update-menu-items ((self histogram-view) (slot-name (eql 'middle-menu))) (let* ((m (slot-value self slot-name))) (wb:check-menu-item m "Fill?" (draw-style self :fill?)))) (defmethod styles-to-subs ((self histogram-view) ) (list :fill? :highlight? :color)) (defmethod free-coord-string ((self histogram-view)) (let ((scale (histogram-scale-of self))) (case scale (:relative-frequency "Relative Frequency") (:density "Density") (t "Frequency")))) (defmethod compute-default-clip-region ((view histogram-view) (on-view view)) :max) (defmethod change-variable ((self histogram-view) &rest args &key var function (transform :none) (draw? t) (link? t) ) (let* ( (axis (axis-of-orientation self)) (other-axis (if (eq axis :x) :y :x)) (free-dir (free-axis self link?))) (flet ((pass-to-links() (loop for v in (variate-links-of self) do (cond ((and (eq axis :x) (typep v '2d-view )) (change-variable v :x var :x-function function :x-transform transform :draw? draw? :link? self )) ((and (eq axis :x) (typep v '2d-view )) (change-variable v :y var :y-function function :y-transform transform :draw? draw? :link? self )) ((typep v '1d-view ) (change-variable v :var var :function function :transform transform :draw? draw? :link? self ) ))))) (cond ((eq free-dir :both) (with-constrained-extents self draw? (pass-to-links) )) ((eq free-dir axis) (with-constrained-extent self axis draw? (pass-to-links))) ((eq free-dir other-axis) (with-constrained-extent self other-axis draw? (apply #'new-variable self :draw? nil args))) (t (apply #'new-variable self :draw? nil args)))))) #| (defmethod coord-strings ((self histogram-view)) (list (coord-string-x self) (coord-string-y self))) |# (defmethod use-x-axis-p ((self histogram-view)) t) (defmethod use-y-axis-p ((self histogram-view)) t)
20,701
Common Lisp
.l
427
34.660422
103
0.514392
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0a95d8b334784fd6d6c0837cb0aee5bbe8a227cf5608fd51d6282dc6fbfcfb97
33,157
[ -1 ]
33,158
range-view.lsp
rwoldford_Quail/source/views/d-views/range-view.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; range-view.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1994 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(range-view ))) (defclass range-view (justification-mixin oriented-line 1d-view simple-view) () (:default-initargs :justification :default :orientation :horizontal) (:documentation "Draws a line for range of data")) (defmethod initialize-instance :after ((self range-view) &key orientation justification) (if (eq justification :default) (if (eq orientation :horizontal) (setf (justification-of self) :bottom) (setf (justification-of self) :right)))) (defmethod compute-line-endpoints ((self range-view) ) (let* ((br (bounding-region-of self)) (xmin (left-of br)) (xmax (right-of br)) (ymin (bottom-of br)) (ymax (top-of br)) pmin pmax) (loop for x in (plot-coords-of self) for s in (case-status-of self) unless (invalid-status-p s) minimize x into minx maximize x into maxx finally (setq pmin minx pmax maxx)) (setf (lines-coords-of self) (ecase (orientation-of self) (:horizontal (ecase (justification-of self) (:top (list (list pmin ymax) (list pmax ymax))) (:bottom (list (list pmin ymin) (list pmax ymin))) (:center (list (list pmin (/ (+ ymin ymax) 2)) (list pmax (/ (+ ymin ymax) 2)))))) (:vertical (ecase (justification-of self) (:left (list (list xmin pmin) (list xmin pmax))) (:bottom (list (list xmax pmin) (list xmax pmax))) (:center (list (list (/ (+ xmin xmax) 2) pmin) (list (/ (+ xmin xmax) 2) pmax))))))))) (defmethod new-variable :before ((self range-view) &key ) (setf (lines-coords-of self) nil)) (defmethod new-case-status ((self range-view) cases status &key ) (declare (ignore cases status)) (compute-line-endpoints self) )
2,885
Common Lisp
.l
68
32.264706
92
0.488212
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6ae36660186d978aedf7670d78612bd02f2f1edc690f13106efd3eed7b5402c9
33,158
[ -1 ]
33,159
smooth.lsp
rwoldford_Quail/source/views/d-views/smooth.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; smooth.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1994 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(smooth set-smooth-par simple-smooth smoothed-2d-point-cloud smooth run-fn))) (defgeneric set-smooth-par (smooth-mixin &key) (:documentation "Sets smoothing parameter.")) (defclass smooth-mixin () ((viewed-object :initarg :viewed-object :initform nil :accessor viewed-object-of :documentation "Object being viewed") (fit-fn :initarg :fit-fn :initform #'running-median :accessor fit-fn-of) (smooth-par :initarg :smooth-par :initform 7 :accessor smooth-par-of) (smoothed-coords :initarg smoothed-coords :initform nil :accessor smoothed-coords-of) ) (:documentation "Computes smoothes coords")) (defclass smoothed-2d-point-cloud (smooth-mixin 2d-point-cloud ) ((middle-menu :allocation :class :initform nil) )) (defclass simple-smooth (smooth-mixin simple-lines) ((middle-menu :allocation :class :initform nil) )) (defclass smooth (smooth-mixin lines ) ((middle-menu :allocation :class :initform nil) )) (defmethod initialize-instance :before ((self smooth) &key (simple? t)) (when (and simple? (eq (class-name (class-of self)) 'smooth)) (change-class self 'simple-smooth) (setf (viewport-compute-method-of self) #'compute-lines-coords-for-viewport))) (defmethod get-menu-items :around ((self smooth-mixin) (slot-name (eql 'middle-menu))) (add-menu-items self (call-next-method) '(("-" nil) ("Smooth Fn" (set-fit-fn )) ("Smooth Par" (set-smooth-par )) ))) (defmethod set-fit-fn ((self smooth-mixin) &key new-fn (draw? t)) (if draw? (erase-view self)) (if (null new-fn) (setf new-fn (wb::prompt-user :result-type t :read-type :read :prompt-string "Enter new smooth function"))) (setf (fit-fn-of self) (get-function new-fn)) (setf (smoothed-coords-of self) nil) (if (typep self 'lines-mixin) (setf (lines-coords-of self) nil)) (if draw? (draw-view self))) (defmethod set-smooth-par ((self smooth-mixin) &key new-par (draw? t)) (if draw? (erase-view self)) (if (null new-par) (setf new-par (wb::prompt-user :result-type t :read-type :eval :prompt-string "Enter new smoothing parameter"))) (setf (smooth-par-of self) new-par) (setf (smoothed-coords-of self) nil) (if (typep self 'lines-mixin) (setf (lines-coords-of self) nil)) (if draw? (draw-view self))) (defmethod new-case-status :before ((self smooth-mixin) cases status &key ) (declare (ignore cases status)) (setf (smoothed-coords-of self) nil) ) (defmethod new-variable :before ((self smooth-mixin) &key ) (setf (smoothed-coords-of self) nil)) (defmethod smooth-par-of ((self smooth-mixin)) (or (slot-value self 'smooth-par) (setf (slot-value self 'smooth-par) (wb::prompt-user :result-type t :read-type :eval :prompt-string "Enter smoothing parameter")))) (defmethod get-cache-coords ((self smooth-mixin)) (or (smoothed-coords-of self) (setf (smoothed-coords-of self) (let* ((raw-coords (call-next-method)) (index+raw (loop for s in (case-status-of self) for i upfrom 0 for r in raw-coords when (active-status-p s) collect (cons i r))) (sorted-coords (sort (copy-list index+raw) #'< :key #'second)) (par (smooth-par-of self)) (smooth-y (funcall (fit-fn-of self) (mapcar #'second sorted-coords) (mapcar #'third sorted-coords) par))) (loop for y in smooth-y for (i) in sorted-coords do (setf (cadr (nth i raw-coords )) y)) raw-coords)))) (defun running-median (x y n) (let ((n2 (truncate n 2)) (len (length x)) (med (get-function 'median))) (loop for i from 0 below len for left = (max 0 (- i n2)) for right = (min (+ i n2) (- len 1)) for win = (subseq y left (+ 1 right)) collect (funcall med win)))) (defun run-fn(fname) (let ((f (get-function fname))) #'(lambda(x y n) (let ((n2 (truncate n 2)) (len (length x)) ) (loop for i from 0 below len for left = (max 0 (- i n2)) for right = (min (+ i n2) (- len 1)) for win = (subseq y left (+ 1 right)) collect (funcall f win)))))) (defun runing-median(x y n) (let ((n2 (truncate n 2)) (len (length x)) (f (get-function 'median)) ) (loop for i from 0 below len for left = (max 0 (- i n2)) for right = (min (+ i n2) (- len 1)) for win = (subseq y left (+ 1 right)) collect (funcall f win))))
5,957
Common Lisp
.l
141
32.35461
92
0.532173
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
cb8d69a545fa73f07f576b71f614f6d26863292b8702360f8f10dc5331f32ee2
33,159
[ -1 ]
33,160
rotating-lines.lsp
rwoldford_Quail/source/views/d-views/rotating-lines.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; rotating-lines.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1995 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(rotating-line-segments rotate-line-segments ))) (defclass rotating-line-segments (line-segments-per-case-mixin rotating-cloud) ((middle-menu :allocation :class :initform nil) ) (:default-initargs :axis-color nil :initform-fn #'get-data-inits-3lists)) ;; move-points is not a good name but move-view is used up. (defmethod move-points ((self rotating-line-segments) &rest args ) (apply #'rotate-line-segments self args)) ;;-------------------------------------------------------------------------------- ;; coords are a list ((x1 x2) (y1 y2) (z1 z2)) for every segment (adjust compute status) ;; plots coords contain a list ((x1 x2) (y1 y2) (z1 z2)) for every segment ;; scaled coords are as above ;; centered-viewport coords are 2 lists for each case (x1 y1 z1) (x2 y2 z2) (defun flatten-tuples(tuples) (loop for c in tuples append (if (and c (every #'listp c)) (apply #'mapcar #'list c)))) (defun list-tuples(tuples &optional (n 2)) (loop for c on tuples by #'(lambda(l) (nthcdr n l)) collect (apply #'mapcar #'list (subseq c 0 n)))) ;;;------------------------------------------------------------ (defmethod compute-scaled-coords ((self rotating-line-segments) &key (cases (cases-of self))) (let* ((coords (coords-of self :cases cases)) (n (coords-per-segment self)) (status (if (eq cases (cases-of self)) (case-status-of self) (loop for c in cases collect (select-case-status self c)))) (scale-method (coords-scale-method-of self))) (if scale-method (list-tuples (funcall (coords-scale-method-of self) (flatten-tuples coords) (loop for s in status append (make-list n :initial-element s))) n) coords) )) ;;;------------------------------------------------------------ (defmethod rotate-paired-coords ((self rotating-line-segments) coords &key (integer? t)) (setf (rotation-of self) (or (rotation-of self) (identity-3d-rotation))) (loop with fn = (if integer? #'round #'identity) with ((x1 y1 z1) (x2 y2 z2) (x3 y3 z3)) float = (rotation-of self) for (a b c) in coords collect (if (and (every #'numberp a) (every #'numberp b) (every #'numberp c)) (loop for ai in a for bi in b for ci in c collect (funcall fn (+ (* x1 ai) (* x2 bi) (* x3 ci))) into newa collect (funcall fn (+ (* y1 ai) (* y2 bi) (* y3 ci))) into newb collect (funcall fn (+ (* z1 ai) (* z2 bi) (* z3 ci))) into newc finally (return (list newa newb newc)))))) (defmethod centered-viewport-coords-of ((self rotating-line-segments) viewport) (let ((n (coords-per-segment self)) (c (scale-data-for-viewport self (flatten-tuples (plot-coords-of self)) viewport))) (if (= n 2) c (loop for co on c by #'(lambda(l) (nthcdr n l)) for x = (subseq co 0 n) collect (first x) append (butlast (loop for xi in (cdr x) collect xi collect xi)))))) (defmethod smallest-bounding-region ((self rotating-line-segments) ) (let ((br (make-region))) (if (cases-of self) (loop for (x y z) in (scaled-coords-of self ) for s in (case-status-of self) when (active-status-p s) maximize (loop for xi in x for yi in y for zi in z maximize (+ (* xi xi) (* yi yi) (* zi zi))) into radius finally (setq radius (sqrt radius)) (if (zerop radius) (incf radius 1)) (setf (bounds-of br) (list (- radius) radius (- radius) radius)))) br)) (defmethod recenter-scaled-coords ((self rotating-line-segments) &optional center) (let (cx cy cz ) (cond ((listp center) (setq cx (first center) cy (second center) cz (third center))) ((eq center :selected) (loop for sub in (subviews-of self) for s in (case-status-of self) for (x y z) in (scaled-coords-of self) when (and (draw-style sub :highlight?) (active-status-p s)) sum (reduce #'+ x) into sumx and sum (reduce #'+ y) into sumy and sum (reduce #'+ z) into sumz and sum (length x) into n finally (unless (zerop n) (setq cx (round (/ sumx n)) cy (round (/ sumy n)) cz (round (/ sumz n)))))) ((eq center :original) (setf (scaled-coords-cache-of self) nil) (setf (plot-coords-cache-of self) nil)) (t nil)) (when (and (numberp cx) (numberp cy) (numberp cz)) (loop for s in (case-status-of self) for (x y z) in (scaled-coords-of self) unless (invalid-status-p s) do (loop for i from 0 below (length x) do (decf (nth i x) cx) (decf (nth i y) cy) (decf (nth i z) cz))) (let* ((r (rotation-of self)) (sx (round (+ (* (elt (elt r 0) 0) cx) (* (elt (elt r 1) 0) cy) (* (elt (elt r 2) 0) cz)))) (sy (round (+ (* (elt (elt r 0) 1) cx) (* (elt (elt r 1) 1) cy) (* (elt (elt r 2) 1) cz)))) (sz (round (+ (* (elt (elt r 0) 2) cx) (* (elt (elt r 1) 2) cy) (* (elt (elt r 2) 2) cz))))) (loop for s in (case-status-of self) for (x y z) in (plot-coords-of self) unless (invalid-status-p s) do (loop for i from 0 below (length x) do (decf (nth i x) sx) (decf (nth i y) sy) (decf (nth i z) sz)) ))))) (defmethod bounds-of-selected ((self rotating-line-segments)) (loop for sub in (subviews-of self) for status in (case-status-of self) for (x y z) in (scaled-coords-of self) when (and (draw-style sub :highlight?) (active-status-p status)) maximize (loop for xi in x for yi in y for zi in z maximize (+ (* xi xi) (* yi yi) (* zi zi))) into radius finally (when radius (setq radius (sqrt radius)) (if (zerop radius) (incf radius 1)) (return (make-region (- radius) radius (- radius) radius))))) ;;;------------------------------------------------------------ (defmethod compute-plot-coords ((self rotating-line-segments)) (rotate-paired-coords self (scaled-coords-of self))) (defmethod expand-styles ((self rotating-line-segments) style &optional default) (let ((n (coords-per-segment self))) (if (<= n 2) (loop for sv in (subviews-of self) collect (draw-style (drawing-style-of sv) style :default default)) (loop for sv in (subviews-of self) for s = (draw-style (drawing-style-of sv) style :default default) append (make-list (- n 1) :initial-element s))))) (defmethod rotate-line-segments ((self rotating-line-segments) &key viewport (direction :y) (steps 1000) (increment (increment-of self))) (unless viewport (setq viewport (if (> (length (viewports-of self)) 1) (which-viewport self) (car (viewports-of self))))) (if (and viewport (not (moving-p self)) (active-viewport-p viewport)) (let* ((temp-coords (centered-viewport-coords-of self viewport)) (axis-color (draw-style self :axis-color)) (colors (expand-styles self :color)) (sizes (expand-styles self :width 1)) (invisible? (expand-styles self :invisible?)) (pcolors (subsubview-styles self :color)) (psymbols (subsubview-styles self :symbol :box)) (psizes (subsubview-styles self :size 4)) (pfill? (subsubview-styles self :fill?)) (pinvisible? (subsubview-styles self :invisible?)) (draw-rate (draw-rate-of self)) (draw-region (get-draw-portion self viewport)) (viewport-coords (viewport-locns-of self viewport)) (ignore-lines (loop with n = (max 1 (- (coords-per-segment self) 1)) with vis = (visible-subs-p self) with status = (case-status-of self) for i in invisible? for j upfrom 0 for k = (truncate j n) collect (or i (not (nth k vis)) (not (active-status-p (nth k status))))) ) (ignore-points (loop with n = (coords-per-segment self) with vis = (visible-subs-p self) with status = (case-status-of self) for i in pinvisible? for j upfrom 0 for k = (truncate j n) collect (or i (not (nth k vis)) (not (active-status-p (nth k status))))) )) (unwind-protect (progn (setf (moving-p self) t) (set-draw-style self :highlight? nil) (loop for s in (subviews-of self) when (draw-style s :highlight?) do (set-drawing-style s :highlight? nil)) (if (draw-axis-p self) (erase-tripod self :viewport viewport)) (if (draw-label-p self) (erase-tripod-labels self :viewport viewport)) (multiple-value-bind (rot end-coords end-axes) (if (typep (car (subviews-of self)) 'connected-points) (wb::rotate-line-segments-points (window-of viewport) temp-coords :axes (if (draw-axis-p self) (centered-viewport-axis-coords-of self viewport)) :axis-color axis-color :width sizes :color colors :invisible? ignore-lines :psize psizes :psymbol psymbols :pfill? pfill? :pcolor pcolors :pinvisible? ignore-points :erase-points viewport-coords :erase-axes (if (draw-axis-p self) (viewport-axis-coords-of self viewport)) :stop-fn (stop-rotate self) :plot-rgn (wb-region draw-region) :direction direction :steps steps :increment increment :viewport-coords? nil :draw-rate draw-rate) (wb::rotate-line-segments (window-of viewport) temp-coords :axes (if (draw-axis-p self) (centered-viewport-axis-coords-of self viewport)) :axis-color axis-color :width sizes :color colors :invisible? ignore-lines :erase-points viewport-coords :erase-axes (if (draw-axis-p self) (viewport-axis-coords-of self viewport)) :stop-fn (stop-rotate self) :plot-rgn (wb-region draw-region) :direction direction :steps steps :increment increment :viewport-coords? nil :draw-rate draw-rate)) (wb::mapply-rotation! rot (rotation-of self) :integer? nil) (setf (plot-coords-cache-of self) nil) (adjust-subviews self ) (set-viewport-locns self :viewport viewport :coords end-coords) (set-viewport-coords self :viewport viewport :coords end-axes) (if (draw-label-p self) (draw-tripod-labels self :viewport viewport)) (loop for vp in (viewports-of self) unless (eq vp viewport) do (remove-viewport-coords self :viewport vp) (set-viewport-locns self :viewport vp) (draw-view self :erase? nil :viewport vp)))) (setf (moving-p self) nil) (draw-view self :erase? t :viewport viewport) )))) (defmethod viewport-locns-of ((self rotating-line-segments) viewport) (setq viewport (or viewport (car (viewports-of self)))) (loop with n = (coords-per-segment self) with m = (* 2 (- n 1)) for sv in (subviews-of self) for s in (case-status-of self) for c = (lines-coords-for-viewport sv (select-viewport sv viewport)) append (if (active-status-p s) (cons (list (caar c) (cdar c)) (butlast (loop for ci in (cdr c ) for a = (list (car ci) (cdr ci)) collect a collect a))) (make-list m)))) (defmethod set-viewport-locns ((self rotating-line-segments) &key viewport coords) (if (and viewport coords) (loop with n = (coords-per-segment self) with m = (* 2 (- n 1)) for sv in (subviews-of self) for vp = (select-viewport sv viewport) for vpc = (viewport-coords-of sv :viewport vp) for c on coords by #'(lambda(l) (nthcdr m l)) do (loop for (x y) in (append (list (car c)) (subseq c 0 m)) by #'cddr for vc in vpc for point-sym in (subviews-of sv) for vp-sv = (select-viewport point-sym vp) do (setf (car vc) x) (setf (cdr vc) y) (set-square-viewport-center vp-sv x y) maximize x into x2 maximize y into y2 minimize x into x1 minimize y into y1 finally (setf (bounds-of vp) (list x1 x2 y1 y2)))) ;; (compute-sub-viewports self viewport) (map-subviews-to-viewport self viewport) )) (defmethod adjust-subviews ((self rotating-line-segments) &optional (new-coords (plot-coords-of self) )) (loop for (x y) in new-coords for l in (sub-view-locns-of self) for sub in (sub-views-of self) for s in (case-status-of self) unless (invalid-status-p s) do (setf (lines-coords-of sub) (mapcar #'list x y)) (setf (bounds-of (bounding-region-of sub)) (list (apply #'min x) (apply #'max x) (apply #'min y) (apply #'max y))) (when (typep sub 'connected-points) (setf (bounds-of l) (list (apply #'min x) (apply #'max x) (apply #'min y) (apply #'max y))) (loop for point-l in (sub-view-locns-of sub) for xi in x for yi in y do (set-square-region-center point-l xi yi))))) (defmethod visible-subviews-p ((self rotating-line-segments)) (loop with br = (bounding-region-of self) with sr = (expt (radius-of br) 2) for (x y z) in (scaled-coords-of self ) for s in (case-status-of self) collect (and (active-status-p s) (<= (loop for xi in x for yi in y for zi in z minimize (+ (* xi xi) (* yi yi) (* zi zi))) sr)))) (defmethod cases-in-selected-region ((self rotating-line-segments)) (let (cx cy cz new-rad ) (loop for sub in (subviews-of self) for s in (case-status-of self) for (x y z) in (scaled-coords-of self) when (and (draw-style sub :highlight?) (active-status-p s)) sum (reduce #'+ x) into sumx and sum (reduce #'+ y) into sumy and sum (reduce #'+ z) into sumz and sum (length x) into n finally (unless (zerop n) (setq cx (round (/ sumx n)) cy (round (/ sumy n)) cz (round (/ sumz n))))) (when (and (numberp cx) (numberp cy) (numberp cz)) (setq new-rad (loop for s in (case-status-of self) for sub in (subviews-of self) for (x y z) in (scaled-coords-of self) when (and (draw-style sub :highlight?) (active-status-p s)) do (loop for i from 0 below (length x) do (decf (nth i x) cx) (decf (nth i y) cy) (decf (nth i z) cz)) and maximize (loop for xi in x for yi in y for zi in z maximize (+ (* xi xi) (* yi yi) (* zi zi))) into radius finally (return radius))) (loop for (x y z) in (scaled-coords-of self ) for vo in (cases-of self) for s in (case-status-of self) when (and (active-status-p s) (loop for i from 0 below (length x) do (decf (nth i x) cx) (decf (nth i y) cy) (decf (nth i z) cz)) (<= (loop for xi in x for yi in y for zi in z maximize (+ (* xi xi) (* yi yi) (* zi zi))) new-rad)) collect vo)))) (defmethod subsubview-styles ((self rotating-line-segments) style &optional default) (when (typep (car (subviews-of self)) 'connected-points) (loop for sv in (subviews-of self) append (loop for s in (subviews-of sv) collect (draw-style (drawing-style-of s) style :default default)))))
20,022
Common Lisp
.l
381
35.377953
106
0.47501
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c6e77c239b57f19c7825a8a8b436a8f30eada438346e553d3c298ad86be38617
33,160
[ -1 ]
33,161
lines.lsp
rwoldford_Quail/source/views/d-views/lines.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; lines.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(lines ))) (defclass lines (brushable-view-mixin pass-draws-to-subviews 2d-view compound-view ) ((middle-menu :allocation :class :initform nil) (order-fn :initform #'< :initarg :order-fn :accessor order-fn-of)) (:default-initargs :dashing nil :width 1 :color *default-curve-color*) (:documentation "Draws line segments objects connecting coords ordered by order-fn")) (defmethod construct-sub-views ((self lines) &key dashing width color segments) (setq segments (subview-arg-list segments 'line-segment)) (let ((coords (active-members self (plot-coords-of self)) ) (fn (order-fn-of self)) (vo (active-members self (cases-of self))) coords-vo) (when fn (setq coords-vo (sort (mapcar #'list coords vo) fn :key #'caar)) (setq coords (mapcar #'car coords-vo)) (setq vo (mapcar #'second coords-vo)) ) (setf (subviews-of self) (loop for case1 in vo for case2 in (cdr vo) for start in coords for end in (cdr coords) for xmin = (min (car start) (car end)) for xmax = (max (car start) (car end)) for ymin = (min (cadr start) (cadr end)) for ymax = (max (cadr start) (cadr end)) for sub-vo = (list case1 case2) collect (apply #'view :data sub-vo :viewed-elements sub-vo :endpoints (list start end) :bounding-region (make-region xmin xmax ymin ymax) :menu? nil :linkable? t :clip-draw? nil :color color :width width :dashing dashing segments ))))) (defmethod init-position-subviews ((self lines) &key ) (loop for sv in (subviews-of self) do (place-subview self sv (bounding-region-of sv)))) (defmethod distance-to-location ((self lines) viewport location) (if (selected-p self viewport location) (let ((locn-c (if (region-p location) (centre-of location) location))) (loop for sv in (subviews-of self) for sv-vp = (select-viewport sv viewport) minimize (distance-to-location sv sv-vp locn-c))) 10000)) (defmethod style-menu-items ((self lines) ) (line-default-middle-items)) (defmethod initialize-instance :before ((self lines) &key simple?) (when (and simple? (eq (class-name (class-of self)) 'lines)) (change-class self 'simple-lines) (setf (viewport-compute-method-of self) #'compute-lines-coords-for-viewport)))
3,717
Common Lisp
.l
78
35.551282
92
0.515325
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
aaa52b4b9340ca0a5752866439546cb01ba7a9a3e6bc9820879a1248c9c8c53f
33,161
[ -1 ]
33,162
fitted-line.lsp
rwoldford_Quail/source/views/d-views/fitted-line.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; fitted-line.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(fitted-line compute-slope&intercept set-fit-fn ))) (defgeneric compute-slope&intercept (fitted-line) (:documentation "Computes slope and intercept from coords and places in slots")) (defgeneric set-fit-fn (fitted-line &key ) (:documentation "sets the fitting function of line")) (defclass fitted-line (line 2d-view simple-view) ((viewed-object :initarg :viewed-object :initform nil :accessor viewed-object-of :documentation "Object being viewed") (fit-fn :initarg :fit-fn :initform #'sreg :accessor fit-fn-of) (middle-menu :allocation :class :initform nil)) (:default-initargs :slope nil :intercept nil) (:documentation "Draws a line fit to coords using fit-fn")) #| (defmethod compute-slope&intercept ((self fitted-line)) (let* ((plot-coords (active-members self (plot-coords-of self))) (xs (mapcar #'first plot-coords)) (ys (mapcar #'second plot-coords))) (multiple-value-bind (intercept slope ) (values-list (funcall (fit-fn-of self) xs ys)) (setf (intercept-of self) intercept) (setf (slope-of self) slope)) ;; sort cases by x (let ((vo-ac (active-members self (cases-of self))) (vo-inac (inactive-members self (cases-of self))) (status-ac (active-members self (case-status-of self))) (status-inac (inactive-members self (case-status-of self))) result) (setq result (sort (mapcar #'list xs vo-ac status-ac) #'< :key #'car )) (setf (cases-of self) (append (mapcar #'second result) vo-inac)) (setf (case-status-of self) (append (mapcar #'third result) status-inac))))) |# (defmethod compute-slope&intercept ((self fitted-line)) (let* ((plot-coords (active-members self (plot-coords-of self))) (xs (mapcar #'first plot-coords)) (ys (mapcar #'second plot-coords))) (multiple-value-bind (intercept slope ) (values-list (funcall (fit-fn-of self) xs ys)) (setf (intercept-of self) intercept) (setf (slope-of self) slope)))) (defmethod slope-of ((self fitted-line)) (unless (slot-value self 'slope) (compute-slope&intercept self)) (slot-value self 'slope)) (defmethod intercept-of ((self fitted-line)) (unless (slot-value self 'intercept) (compute-slope&intercept self)) (slot-value self 'intercept)) (defmethod new-variable ((self fitted-line) &key ) (declare (ignorable self)) ;(declare (ignore self)) ; 29JUL2023 (call-next-method)) (defmethod new-variable :before ((self fitted-line) &key ) (setf (slope-of self) nil) (setf (intercept-of self) nil)) (defmethod new-case-status ((self fitted-line) cases status &key ) (declare (ignorable cases status)) ;(declare (ignore cases status)) ; 29JUL2023 (compute-slope&intercept self) (compute-line-endpoints self) ) (defmethod get-menu-items ((self fitted-line) (slot-name (eql 'middle-menu))) '(("-" nil) ("Fit Fn" (set-fit-fn )) ("Slope" (set-line-slope )) ("Intercept" (set-line-intercept ) ))) (defmethod set-fit-fn ((self fitted-line) &key new-fn (draw? t)) (if draw? (erase-view self)) (if (null new-fn) (setf new-fn (wb::prompt-user :result-type t :read-type :read :prompt-string "Enter new line function"))) (setf (fit-fn-of self) (get-function new-fn)) (compute-slope&intercept self) (compute-line-endpoints self) (if draw? (draw-view self)))
4,619
Common Lisp
.l
103
36.427184
92
0.572407
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a1d6402397a16a4d344167b305081fffd09f151015a23c7721323cd9100f3042
33,162
[ -1 ]
33,163
barchart.lsp
rwoldford_Quail/source/views/d-views/barchart.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; barchart.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1994 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) ;;;---------------------------------------------------------------------------------- (defclass barchart (histogram-view) ((middle-menu :allocation :class :initform nil)) (:default-initargs :color *default-bar-color* :fill? *default-bar-fill?*)) (defmethod valid-coord-test ((self barchart) c) c) (defmethod smallest-bounding-region ((self barchart) ) (let ((coords (active-members self (plot-coords-of self))) min max hgt) (if (cases-of self) (progn (loop for c in coords when (numberp c) maximize c into amax and minimize c into amin finally (setq min (or amin 0) max (or 1 amax))) (setq hgt (apply #'max (bar-heights-of self))) (if (eq (orientation-of self) :vertical) (make-region 0.0 hgt min max) (make-region min max 0.0 hgt ) )) (make-region)))) (defmethod bar-heights-of ((self barchart)) (compute-bar-heights self (histogram-scale-of self))) (defmethod construct-sub-views ((self barchart) &key bars bar-coords fill? color) (let* ((group-vals (or bar-coords (remove-duplicates (coords-of self) :test #'equal))) (orientation (orientation-of self)) (style-arglist (append bars (list :color color :fill? fill? ))) sub-styles sub-vos) (setq bars (subview-arg-list bars 'bar)) (multiple-value-setq ( sub-vos sub-styles) (group-viewed-objs self #'(lambda(x) (position x group-vals :test #'equal)) (length group-vals) (get-viewed-obj-styles self :fill? (getf style-arglist :fill?) :color (getf style-arglist :color)))) (setf (subviews-of self) (loop for vos in sub-vos for vo-style in sub-styles collect (apply #'view :data vos :check-style? t :orientation orientation :drawing-style vo-style bars))) ) ; end let ) (defmethod init-position-subviews ((self barchart) &key) (let ((br (bounding-region-of self)) (n (length (subviews-of self))) lo w hi) (when (subviews-of self) (if (eq (orientation-of self) :vertical) (setq lo (bottom-of br) hi (top-of br)) (setq lo (left-of br) hi (right-of br))) (setq w (/ (- hi lo) n)) (loop with reg with bounds = (or (break-points-of self) (append (loop repeat n for x from lo by w collect x) (list hi))) for bar in (subviews-of self) for b1 in bounds for b2 in (cdr bounds) for hgt in (bar-heights-of self) do (setq reg (if (eq (orientation-of self) :vertical) (make-region 0.0 hgt b1 b2 ) (make-region b1 b2 0.0 hgt) )) (place-subview self bar reg)) ))) (defmethod get-menu-items ((self barchart) (slot-name (eql 'middle-menu))) `(("-" nil) ("Scale" nil "" :sub-items (("Frequency" (set-histogram-scale :scale :frequency)) ("RelFrequency" (set-histogram-scale :scale :relative-frequency)) ))))
4,286
Common Lisp
.l
102
30.22549
92
0.473658
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e79230166a518365c1a6513528ff4982eed2f2b9bd454cc31caadba27e9ff448
33,163
[ -1 ]
33,164
rotation.lsp
rwoldford_Quail/source/views/d-views/rotation.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; rotation.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(rotating-cloud recenter-scaled-coords rotate-points set-rotation scaled-axis-coords-of compute-scaled-axis-coords viewport-axis-coords-of draw-tripod erase-tripod set-draw-axis-p set-draw-label-p set-increment))) (defclass rotating-cloud (viewport-coords-cache-mixin square-view-mixin moving-cloud-mixin) ( (middle-menu :allocation :class :initform nil) (style-keys :initform '(:font :size :fill? :color :axis-color) :allocation :class) (rotation :initarg :rotation :initform nil :accessor rotation-of) (scaled-axis-coords-cache :initform nil :accessor scaled-axis-coords-cache-of) (draw-axis? :initform t :initarg :draw-axis? :accessor draw-axis-p) (draw-label? :initform t :initarg :draw-label? :accessor draw-label-p) (increment :initform (/ pi 30) :initarg :increment :accessor increment-of) (x-text :initform nil :initarg :x-text :accessor x-text-of) (y-text :initform nil :initarg :y-text :accessor y-text-of) (z-text :initform nil :initarg :z-text :accessor z-text-of) ) (:default-initargs :font wb::*very-small-graphics-font* :axis-color *default-axis-color* :viewport-compute-method #'compute-viewport-axis-coords) ) (defgeneric recenter-saled-coords (rotating-cloud &optional center) (:documentation "Shifts the scaled coords so that center appears at the ~ viewports center. ~ If center is :selected the center of highlit subviews is used. ~ If center is :original the original (default) center is used. ")) (defgeneric rotate-points (cloud &key viewport) (:documentation "rotates the cloud in viewport")) (defgeneric set-rotation (cloud &key rotation) (:documentation "sets rotation of cloud. Default is identity")) (defgeneric compute-scaled-axis-coords (cloud) (:documentation "computes and returns standardized origin and endpoints of axes")) (defgeneric scaled-axis-coords-of (cloud) (:documentation "returns standardized origin and endpoints of axes")) (defgeneric viewport-axis-coords-of (cloud viewport) (:documentation "returns the origin and endpoints of axes in viewport coords")) (defgeneric draw-tripod (cloud &key viewport labels? ) (:documentation "draws a tripod for axes")) (defgeneric erase-tripod (cloud &key viewport labels? ) (:documentation "erases tripod for axes")) (defgeneric set-draw-axis-p (cloud val ) (:documentation "sets the value of accessor draw-axis-p and redraws")) (defgeneric set-draw-label-p (cloud val ) (:documentation "sets the value of accessor draw-label-p and redraws")) (defgeneric set-increment (cloud val ) (:documentation "sets the stepsize for rotation")) ;;-------------------------------------------------------------------------------- (defmethod description-string ((self rotating-cloud) ) (format nil "~A ~% X: ~A Y: ~A Z: ~A" (call-next-method) (first (rotation-of self)) (second (rotation-of self)) (third (rotation-of self)))) (defun identity-3d-rotation () "a list of lists for an identity rotation in 3d" (list (list 1 0 0) ( list 0 1 0) ( list 0 0 1))) #| ;; same as below which works in mcl 2.0.1 but not in mcl 2.0 (defmethod rotate-coords ((self rotating-cloud) coords &key (integer? t)) (setf (rotation-of self) (or (rotation-of self) (identity-3d-rotation))) (loop with fn = (if integer? #'round #'identity) with rot = (rotation-of self) with x1 = (elt (elt rot 0) 0) with x2 = (elt (elt rot 1) 0) with x3 = (elt (elt rot 2) 0) with y1 = (elt (elt rot 0) 1) with y2 = (elt (elt rot 1) 1) with y3 = (elt (elt rot 2) 1) with z1 = (elt (elt rot 0) 2) with z2 = (elt (elt rot 1) 2) with z3 = (elt (elt rot 2) 2) for (a b c) in coords collect (if (and (numberp a) (numberp b) (numberp c)) (list (funcall fn (+ (* x1 a) (* x2 b) (* x3 c))) (funcall fn (+ (* y1 a) (* y2 b) (* y3 c))) (funcall fn (+ (* z1 a) (* z2 b) (* z3 c))))))) |# (defmethod rotate-coords ((self rotating-cloud) coords &key (integer? t)) (setf (rotation-of self) (or (rotation-of self) (identity-3d-rotation))) (loop with fn = (if integer? #'round #'identity) with ((x1 y1 z1) (x2 y2 z2) (x3 y3 z3)) float = (rotation-of self) for (a b c) in coords collect (if (and (numberp a) (numberp b) (numberp c)) (list (funcall fn (+ (* x1 a) (* x2 b) (* x3 c))) (funcall fn (+ (* y1 a) (* y2 b) (* y3 c))) (funcall fn (+ (* z1 a) (* z2 b) (* z3 c))))))) (defmethod compute-plot-coords ((self rotating-cloud)) (rotate-coords self (scaled-coords-of self))) (defmethod centered-viewport-axis-coords-of ((self rotating-cloud) viewport) (scale-data-for-viewport self (rotate-coords self (scaled-axis-coords-of self )) viewport)) (defmethod set-bounding-region :after ((self rotating-cloud) &key &allow-other-keys) (setf (scaled-axis-coords-cache-of self) nil)) (defmethod smallest-bounding-region ((self rotating-cloud) ) (let ((br (make-region))) (if (cases-of self) (loop for (x y z) in (scaled-coords-of self ) for s in (case-status-of self) when (active-status-p s) maximize (+ (* x x) (* y y) (* z z)) into radius finally (setq radius (ceiling (sqrt radius))) (if (zerop radius) (incf radius 1)) (setf (bounds-of br) (list (- radius) radius (- radius) radius)))) br)) (defmethod recenter-scaled-coords ((self rotating-cloud) &optional center) (let (cx cy cz ) (cond ((listp center) (setq cx (first center) cy (second center) cz (third center))) ((eq center :selected) (loop for sub in (subviews-of self) for s in (case-status-of self) for (x y z) in (scaled-coords-of self) when (and (draw-style sub :highlight?) (active-status-p s)) sum x into sumx and sum y into sumy and sum z into sumz and count 1 into n finally (unless (zerop n) (setq cx (round (/ sumx n)) cy (round (/ sumy n)) cz (round (/ sumz n)))))) ((eq center :original) (setf (scaled-coords-cache-of self) nil) (setf (plot-coords-cache-of self) nil)) (t nil)) (when (and (numberp cx) (numberp cy) (numberp cz)) (loop for s in (case-status-of self) for xyz in (scaled-coords-of self) unless (invalid-status-p s) do (decf (car xyz) cx) (decf (second xyz) cy) (decf (third xyz) cz)) (let* ((r (rotation-of self)) (sx (round (+ (* (elt (elt r 0) 0) cx) (* (elt (elt r 1) 0) cy) (* (elt (elt r 2) 0) cz)))) (sy (round (+ (* (elt (elt r 0) 1) cx) (* (elt (elt r 1) 1) cy) (* (elt (elt r 2) 1) cz)))) (sz (round (+ (* (elt (elt r 0) 2) cx) (* (elt (elt r 1) 2) cy) (* (elt (elt r 2) 2) cz))))) (loop for s in (case-status-of self) for xyz in (plot-coords-of self) unless (invalid-status-p s) do (decf (car xyz) sx) (decf (second xyz) sy) (decf (third xyz) sz)))))) (defmethod bounds-of-selected ((self rotating-cloud)) (loop for sub in (subviews-of self) for status in (case-status-of self) for (x y z) in (scaled-coords-of self) when (and (draw-style sub :highlight?) (active-status-p status)) maximize (+ (* x x) (* y y) (* z z)) into radius finally (when radius (setq radius (ceiling (sqrt radius))) (if (zerop radius) (incf radius 1)) (return (make-region (- radius) radius (- radius) radius))))) (defmethod new-bounds ((self rotating-cloud) &key (region :compute) pretty?) (unless (region-p region) (setq region (case region (:prompt (apply #'make-region (wb::prompt-user :result-type 'list :read-type :read :prompt-string "(left right bottom top)"))) (:original (recenter-scaled-coords self :original) (adjust-subviews self ) (original-bounds self :draw? t) nil) (t (recenter-scaled-coords self :selected) (adjust-subviews self ) (setq region (bounds-of-selected self)) region)))) (when (region-p region) (change-bounding-region self region :pretty? pretty?)) ) (defmethod stop-rotate ((self rotating-cloud)) (if (wb::mouse-down-p) #'(lambda() (not (wb::mouse-down-p))) #'(lambda() (wb::mouse-down-p)))) (defmethod rotate-points ((self rotating-cloud) &key viewport (direction :y) (steps 1000) (increment (increment-of self))) (unless viewport (setq viewport (if (> (length (viewports-of self)) 1) (which-viewport self) (car (viewports-of self))))) (if (and viewport (not (moving-p self)) (active-viewport-p viewport)) (let* ((temp-coords (centered-viewport-coords-of self viewport)) (fill? (subview-styles self :fill?)) (axis-color (draw-style self :axis-color)) (colors (subview-styles self :color)) (symbols (subview-styles self :symbol :box)) (sizes (subview-styles self :size 4)) (invisible? (subview-styles self :invisible?)) (draw-region (get-draw-portion self viewport)) (viewport-coords (viewport-locns-of self viewport)) (ignore-points (loop for i in invisible? for s in (case-status-of self) for vis in (visible-subs-p self) collect (or i (not vis) (not (active-status-p s))))) (draw-rate (draw-rate-of self)) ) (unwind-protect (progn (setf (moving-p self) t) (set-draw-style self :highlight? nil) (loop for s in (subviews-of self) when (draw-style s :highlight?) do (set-drawing-style s :highlight? nil)) (if (draw-axis-p self) (erase-tripod self :viewport viewport)) (if (draw-label-p self) (erase-tripod-labels self :viewport viewport)) (multiple-value-bind (rot end-coords end-axes) (wb::rotate-point-cloud (window-of viewport) temp-coords :axes (if (draw-axis-p self) (centered-viewport-axis-coords-of self viewport)) :axis-color axis-color :size sizes :symbol symbols :fill? fill? :color colors :invisible? ignore-points :erase-points viewport-coords :erase-axes (if (draw-axis-p self) (viewport-axis-coords-of self viewport)) :stop-fn (stop-rotate self) :plot-rgn (wb-region draw-region) :direction direction :steps steps :increment increment :viewport-coords? nil :draw-rate draw-rate) (wb::mapply-rotation! rot (rotation-of self) :integer? nil) (setf (plot-coords-cache-of self) nil) (adjust-subviews self ) (set-viewport-locns self :viewport viewport :coords end-coords) (set-viewport-coords self :viewport viewport :coords end-axes) (if (draw-label-p self) (draw-tripod-labels self :viewport viewport)) (loop for vp in (viewports-of self) unless (eq vp viewport) do (remove-viewport-coords self :viewport vp) (set-viewport-locns self :viewport vp) (draw-view self :erase? nil :viewport vp)))) (setf (moving-p self) nil) (draw-view self :erase? t :viewport viewport) )))) (defmethod set-rotation ((self rotating-cloud) &key (rotation (identity-3d-rotation))) (clear-view-viewport self) (setf (rotation-of self) rotation) (setf (plot-coords-cache-of self) nil) (remove-viewport-coords self) (adjust-subviews self ) (set-viewport-locns self ) (draw-view self :erase? nil)) (defmethod erase-view ((self rotating-cloud) &key viewport) (clear-view-viewport self :viewport viewport)) (defmethod draw-view :after ((self rotating-cloud) &key viewport) (when (draw-axis-p self) (draw-tripod self :viewport viewport))) (defmethod set-drawing-style :around ((self rotating-cloud) &key) (when (draw-axis-p self) (erase-tripod self )) (call-next-method) (when (draw-axis-p self) (draw-tripod self ))) (defmethod initialize-instance :after ((self rotating-cloud) &key x-text y-text z-text ) (unless x-text (setf (x-text-of self) (coord-string-x self))) (unless y-text (setf (y-text-of self) (coord-string-y self))) (unless z-text (setf (z-text-of self) (coord-string-z self)))) ;;; axes (defmethod compute-scaled-axis-coords ((self rotating-cloud)) (let* ((r (radius-of (bounding-region-of self))) (m (round (* 0.8 r)))) (list (list 0 0 0) (list m 0 0) (list 0 m 0) (list 0 0 m)))) (defmethod scaled-axis-coords-of ((self rotating-cloud) ) (or (scaled-axis-coords-cache-of self) (setf (scaled-axis-coords-cache-of self) (compute-scaled-axis-coords self )))) (defmethod compute-viewport-axis-coords ((self rotating-cloud) viewport) ;; returns the coords of self scaled to the viewport for rotation (setq viewport (or viewport (car (viewports-of self)))) (let* ((temp (centered-viewport-axis-coords-of self viewport)) (shift (wb::make-shift-transform (wb-region viewport)))) (wb::mapply-transform shift temp))) (defmethod viewport-axis-coords-of ((self rotating-cloud) viewport) (viewport-coords-of self :viewport viewport)) (defmethod draw-tripod ((self rotating-cloud) &key viewport (operation :default) (labels? (draw-label-p self))) (loop for vp in (if viewport (list viewport) (viewports-of self)) when (active-viewport-p vp) do (loop with points = (viewport-axis-coords-of self vp) with bw = (window-of vp) with o = (first points) with font = (draw-style self :font) with color = (draw-style self :axis-color) for p in (cdr points) for c in (list (x-text-of self) (y-text-of self) (z-text-of self)) do (wb::canvas-draw-line bw (car o) (cadr o) (car p ) (cadr p) :operation operation :color color :width 1) (if labels? (wb::canvas-draw-string bw c :font font :color color)) ))) (defmethod erase-tripod ((self rotating-cloud) &key viewport (labels? (draw-label-p self))) (loop for vp in (if viewport (list viewport) (viewports-of self)) when (active-viewport-p vp) do (loop with points = (viewport-axis-coords-of self vp) with bw = (window-of vp) with font = (draw-style self :font) with o = (first points) for p in (cdr points) for c in (list (x-text-of self) (y-text-of self) (z-text-of self)) do (wb::canvas-erase-line bw (car o) (cadr o) (car p ) (cadr p) :operation :boole-andc1 :width 1 ) (when labels? (wb::canvas-erase-string bw c :font font )) ) ) ) (defmethod draw-tripod-labels ((self rotating-cloud) &key viewport ) (loop for vp in (if viewport (list viewport) (viewports-of self)) when (active-viewport-p vp) do (loop with points = (viewport-axis-coords-of self vp) with bw = (window-of vp) with font = (draw-style self :font) with color = (draw-style self :axis-color) for p in (cdr points) for c in (list (x-text-of self) (y-text-of self) (z-text-of self)) do (wb::canvas-move-to bw (car p ) (cadr p) ) (wb::canvas-draw-string bw c :font font :color color)))) (defmethod erase-tripod-labels ((self rotating-cloud) &key viewport ) (loop for vp in (if viewport (list viewport) (viewports-of self)) when (active-viewport-p vp) do (loop with points = (viewport-axis-coords-of self vp) with bw = (window-of vp) with font = (draw-style self :font) for p in (cdr points) for c in (list (x-text-of self) (y-text-of self) (z-text-of self)) do (wb::canvas-move-to bw (car p ) (cadr p) ) (wb::canvas-erase-string bw c :font font )))) #| (defmethod change-variable :around ((self rotating-cloud) &rest args &key (draw? t)) (apply #'new-variable self :draw? draw? args)) |# (defmethod styles-to-subs ((self rotating-cloud) ) (list :highlight? :fill? :size :color )) #| 26SEP2023 the method immediately below is to be retained email from rwo 26SEP2023 (defmethod get-rotation-menu-items ((self rotating-cloud) ) `(("Start" (set-rotation )) ("Axes" (set-draw-axis-p :toggle)) ("Labels" (set-draw-label-p :toggle)) ("Font" nil "" :sub-items ,(font-menu-items)) ("-" nil) )) |# (defmethod get-rotation-menu-items ((self rotating-cloud) ) `(("Start" nil "" :sub-items (("XY" (set-rotation )) ("XZ" (set-rotation :rotation ,(list (list 1 0 0) (list 0 0 1) (list 0 1 0)))) ("YX" (set-rotation :rotation ,(list (list 0 1 0) (list 1 0 0) (list 0 0 1)))) ("YZ" (set-rotation :rotation ,(list (list 0 1 0) (list 0 0 1) (list 1 0 0)))) ("ZX" (set-rotation :rotation ,(list (list 0 0 1) (list 1 0 0) (list 0 1 0)))) ("ZY" (set-rotation :rotation ,(list (list 0 0 1) (list 0 1 0) (list 1 0 0)))))) ("Axes" (set-draw-axis-p :toggle)) ("Labels" (set-draw-label-p :toggle)) ("Font" nil "" :sub-items ,(font-menu-items)) ("-" nil) )) (defmethod update-menu-items :before ((self rotating-cloud) (slot-name (eql 'middle-menu))) (let* ((m (slot-value self slot-name))) (wb::check-menu-item m "Axes" (draw-axis-p self )) (wb::check-menu-item m "Labels" (draw-label-p self )))) (defmethod remake-menu :after ((self rotating-cloud ) (slot-name (eql 'middle-menu)) &optional middle) (setf (slot-value self 'middle-menu) (or middle (append (get-rotation-menu-items self) (slot-value self 'middle-menu) )))) (defmethod set-draw-axis-p ((self rotating-cloud) val) (if (eq val :toggle) (setq val (not (draw-axis-p self)))) (setf (draw-axis-p self) val) (if (null val) (setf (draw-axis-p self) nil)) (if val (draw-tripod self) (erase-tripod self :labels? t))) (defmethod set-draw-label-p ((self rotating-cloud) val) (if (eq val :toggle) (setq val (not (draw-label-p self)))) (if val (if (draw-axis-p self) (setf (draw-label-p self) t)) (setf (draw-label-p self) nil)) (if (draw-label-p self) (draw-tripod-labels self) (erase-tripod-labels self))) (defmethod set-increment ((self rotating-cloud) val) (case val (:faster (setq val (* (increment-of self) 1.5))) (:slower (setq val (/ (increment-of self) 1.5))) (t nil)) (setf (increment-of self) val)) (defmethod reposition-view :after ((self rotating-cloud) &key default-positions draw?) (declare (ignore default-positions)) (when (and draw? (draw-axis-p self)) (draw-tripod self ))) (defmethod new-variable :before ((self rotating-cloud) &key draw?) (if (and draw? (draw-axis-p self)) (erase-tripod self )) (setf (scaled-axis-coords-cache-of self) nil) (setf (plot-coords-cache-of self) nil) (setf (viewport-coords-cache-of self) nil) ) (defmethod new-variable :after ((self rotating-cloud) &key draw?) (setf (x-text-of self) (coord-string-x self)) (setf (y-text-of self) (coord-string-y self)) (setf (z-text-of self) (coord-string-z self)) (if (and draw? (draw-axis-p self)) (draw-tripod self )) ) (defmethod new-case-status :before ((self rotating-cloud) cases status &key rescale?) (declare (ignore cases status)) (when rescale? (setf (scaled-axis-coords-cache-of self) nil) (setf (plot-coords-cache-of self) nil) (setf (viewport-coords-cache-of self) nil) )) (defmethod new-case-status :after ((self rotating-cloud) cases status &key rescale?) (declare (ignore cases status)) (when rescale? (adjust-subviews self))) (defmethod move-points ((self rotating-cloud) &rest args ) (apply #'rotate-points self args)) (defmethod reset-bounding-region ((self rotating-cloud) &key (draw? nil ) ) (if draw? (erase-view self)) (set-bounding-region self) (remap-to-viewports self :erase? nil :draw? draw?) ) (defmethod visible-subviews-p ((self rotating-cloud)) (loop with br = (bounding-region-of self) with sr = (expt (radius-of br) 2) for (x y z) in (scaled-coords-of self ) for s in (case-status-of self) collect (and (active-status-p s) (<= (+ (* x x) (* y y) (* z z)) sr)))) (defmethod margin-string-bottom ((self rotating-cloud)) (coord-strings self)) (defmethod margin-string-top ((self rotating-cloud)) (coord-strings self)) (defmethod margin-string-left ((self rotating-cloud)) ) (defmethod margin-string-right ((self rotating-cloud)) ) (defmethod use-y-axis-p ((self rotating-cloud)) nil) (defmethod use-x-axis-p ((self rotating-cloud)) nil)
25,284
Common Lisp
.l
523
35.650096
104
0.542593
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
91d719db89339d3f46d7b825a0f642df1243054e2f3fb218a0f963039b1ac900
33,164
[ -1 ]
33,165
interval-view.lsp
rwoldford_Quail/source/views/d-views/interval-view.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; interval-view.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1994 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(interval-view ))) (defclass interval-view (justification-mixin oriented-line 1d-view simple-view) ((min-fn :initarg :min-fn :initform #'(lambda(n) (apply #'min n)) :accessor min-fn-of) (max-fn :initarg :max-fn :initform #'(lambda(n) (apply #'max n)) :accessor max-fn-of)) (:default-initargs :justification :default :orientation :horizontal) (:documentation "Draws a line for range of data")) (defmethod compute-line-endpoints ((self interval-view) ) (if (eq (justification-of self) :default) (if (eq (orientation-of self) :horizontal) (setf (justification-of self) :bottom) (setf (justification-of self) :right))) (let* ((br (bounding-region-of self)) (xmin (left-of br)) (xmax (right-of br)) (ymin (bottom-of br)) (ymax (top-of br)) (plot-coords (active-members self (plot-coords-of self))) (pmin (funcall (min-fn-of self) plot-coords)) (pmax (funcall (max-fn-of self) plot-coords))) (setf (lines-coords-of self) (ecase (orientation-of self) (:horizontal (ecase (justification-of self) (:top (list (list pmin ymax) (list pmax ymax))) (:bottom (list (list pmin ymin) (list pmax ymin))) (:center (list (list pmin (/ (+ ymin ymax) 2)) (list pmax (/ (+ ymin ymax) 2)))))) (:vertical (ecase (justification-of self) (:left (list (list xmin pmin) (list xmin pmax))) (:right (list (list xmax pmin) (list xmax pmax))) (:center (list (list (/ (+ xmin xmax) 2) pmin) (list (/ (+ xmin xmax) 2) pmax))))))))) (defmethod new-variable :before ((self interval-view) &key ) (setf (lines-coords-of self) nil)) (defmethod new-case-status ((self interval-view) cases status &key ) (declare (ignore cases status)) (compute-line-endpoints self) )
2,989
Common Lisp
.l
68
33.485294
92
0.485273
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
cd14ee92a1a967b2e9a3f6c658ae68638d44e8babdecf38b454c2df32896c725
33,165
[ -1 ]
33,167
simple-case-object.lsp
rwoldford_Quail/source/views/views-data/simple-case-object.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; simple-case-object.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright 1993 (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1993 George Washington University ;;; R.W. Oldford 1993 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(simple-case-object case-data-of identifier-of make-case-object-class))) (defclass simple-case-object () ((identifier :initform NIL :initarg :identifier :accessor identifier-of) (parent-dataset :initform NIL :initarg :parent-dataset :accessor parent-dataset-of) (case-data :initform NIL :initarg :case-data :accessor case-data-of) (case-vars :initform NIL :initarg :case-vars :accessor case-vars-of)) (:documentation "A simple structure representing a case.")) (defun make-case-object-class(class-name ) (eval `(defclass ,class-name(simple-case-object) () ))) (defmethod dataset-p ((thing simple-case-object)) T) (defmethod eq-dataset ((d1 simple-case-object) (d2 simple-case-object)) (or (eq d1 d2) (eq-dataset (case-data-of d1) (case-data-of d2)))) (defmethod eq-dataset ((d1 simple-case-object) (d2 T)) (eq-dataset (case-data-of d1) d2)) (defmethod eq-dataset (d1 (d2 simple-case-object)) (eq-dataset (case-data-of d2) d1)) (defmethod list-cases ((c simple-case-object)) (list c)) (defmethod list-variates ((c simple-case-object)) (or (case-vars-of c) (list-variates (case-data-of c)))) (defmethod value-of ((c simple-case-object) (v fixnum) &key (default :error) (safe? T) ) (if (null safe?) (qk::eref (case-data-of c) v) (let ((case-vals (case-data-of c))) (if (>= v (qk::number-of-elements case-vals)) default (qk::eref case-vals v))))) (defmethod value-of ((c simple-case-object) var &key (default :error) (safe? T)) (if (null safe?) (qk::eref (case-data-of c) (position var (case-vars-of c) :test #'eq-variates)) (let* ((case-vals (case-data-of c)) (ans1 (value-of case-vals var :default :value-of-failed))) (if (eq ans1 :value-of-failed) (let* ((cv (case-vars-of c)) (v (position var cv :test #'eq-variates))) (if (or (not (integerp v)) (>= v (qk::number-of-elements case-vals))) default (qk::eref case-vals v))) ans1)))) (defmethod display ((c simple-case-object) &rest keyword-args &key &allow-other-keys) (apply #'display (case-data-of c) keyword-args))
2,983
Common Lisp
.l
67
39.507463
137
0.578267
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d83adb2e758ab8011aacd5ea8f31c48fb91b7a73582a3c4f292b077378ac194f
33,167
[ -1 ]
33,168
data-ref-arrays.lsp
rwoldford_Quail/source/views/views-data/data-ref-arrays.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; data-ref-arrays.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; DATASETS AS ref-arrayS ;;; ;;; First index (row if a matrix) identifies the case. ;;; Other dimensions used to identify variates. ;;; ;;; ... rwo ;;; (defmethod make-dataset-from-vars ((var quail-kernel:ref-array) &rest other-vars) ;; this doesn't do what I'd anticipate- create a 2d-array by glueing ;; together 2 or more 1d-arrays colwise cbh 2/17/93 ;; Works for me! .... rwo Feb 10 94 (apply #'quail-kernel:cglue var other-vars )) (defmethod make-data-subset ((d quail-kernel:ref-array) case-list &key) (if case-list (let ((specs (if (typep (first case-list) 'quail-kernel::dimensioned-ref-object) (qk::specs-of (first case-list))))) (setq specs (and specs (listp specs) (copy-list specs))) (if specs (progn (loop for c in (rest case-list) for c-specs = (qk::specs-of c) do (loop for i from 0 to (- (length specs) 1) for a = (elt c-specs i) do (cond ((eq (elt specs i) T) NIL) ((eq a T) (setf (elt specs i) T)) (T (setf (elt specs i) (append (elt specs i) a)))))) (if (qk::direct-ref-p d) (apply #'qk::ref d (append specs (list :shape t))) (apply #'qk::ref (qk::ref-obj-of d) (append specs (list :shape t))))) (apply #'qk::rglue case-list))))) (defmethod dataset-p ((d quail-kernel:ref-array)) T) (defmethod eq-dataset ((d1 quail-kernel:ref-array) (d2 quail-kernel:ref-array)) ;; (quail-kernel:ref-eq d1 d2) changed this 6/16/97 cbh (eq d1 d2)) (defmethod list-cases ((d quail-kernel:ref-array)) (let ((dim (quail-kernel:dimensions-of d))) (if dim (loop for i from 0 below (first dim) collect (quail-kernel:ref d i)) (list d))) ) (defmethod extract-case ((d quail-kernel:ref-array) (index integer)) (quail-kernel:ref d index)) (defmethod list-variates ((d quail-kernel:ref-array)) (let ((p (second (quail-kernel:dimensions-of d)))) (if p (loop for i from 0 below p collect i) (list 0) ))) (defmethod identifier-of ((c quail-kernel:ref-array)) NIL) #| (defmethod value-of ((c quail-kernel:ref-array) var &key) (quail-kernel:eref c var)) |# #| (defmethod case-val ((c quail-kernel:ref-array) (var number) &key (default var)) (multiple-value-bind (result error?) (ignore-errors (quail-kernel:eref c var)) (if error? (if (eq default :error) (quail-error "~A has no value for ~A" c var) default) result))) |# (defmethod value-of ((c quail-kernel:ref-array) (var fixnum) &key (default :error)) (multiple-value-bind (result error?) (ignore-errors (quail-kernel:eref c var)) (if error? default result)))
3,799
Common Lisp
.l
100
30.91
92
0.513003
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
210bad672eadfa7e008ae13a90338359b7d2dfdbcdf9cec1397fca244d0dbbb5
33,168
[ -1 ]
33,169
data-lists.lsp
rwoldford_Quail/source/views/views-data/data-lists.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; data-lists.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; DATASETS AS LISTS ;;; ;;; Simple datasets, consisting of a list of lists, each sublist is a "case". ;;; ;;; Cases are also regarded as kinds of datasets. Should a list eg (a b c) ;;; be regarded as a dataset of a single case or a dataset of 3 cases? ;;; We resolve this by deciding that: ;;; If the first object a is itself a dataset then (a b c) is a dataset of 3 cases. ;;; Otherwise, (a b c) is a dataset of a single case. ;;; ;;; Therefore (3 4 2) is treated as a dataset of a single case because ;;; numbers themselves are not dataset-p. ;;; However, the array object created by (array '(3 4 2)) is treated differently, ;;; because the "convention" for arrays is that (array '(3 4 2)) should be treated ;;; as a 3 x 1 array, that is, a dataset of 3 cases. (defmethod make-dataset-from-vars ((var list) &rest other-vars) (apply #'mapcar #'list var other-vars)) (defmethod make-data-subset((d list) case-list &key) case-list) (defmethod dataset-p ((d list)) (not (null d))) (defmethod eq-dataset ((d1 list) (d2 list)) (and d1 d2 (or (eq d1 d2) (and (= (length d1) (length d2)) (every #'eq-dataset d1 d2))))) (defmethod list-cases ((d list)) ;; If d is already a list of datasets then d itself is returned. ;; Otherwise d is interpreted as a dataset with a single case. (cond ((null d) nil) ((dataset-p (car d)) d) (t (list d)))) ;; following changed from fixnum to integer by Greg Anglin 93 12 ;; to support Allegro port (defmethod extract-case ((d list) (index integer)) (elt (list-cases d) index)) (defmethod list-variates ((d list)) (cond ((null d) nil) ((dataset-p (car d)) (list-variates (car d))) (t (loop for i from 0 below (length d) collect i)))) #| (defmethod case-val ((c list) (v fixnum) &key (default :error)) (if (>= v (length c)) default (elt c v))) |# (defmethod value-of ((c list) (v fixnum) &key (default :error)) (if (>= v (length c)) default (elt c v)))
2,953
Common Lisp
.l
77
33.532468
92
0.531439
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e69d6e57343b8486f73c62121b8ae718c2dfa4cae63a1b95a26b7d2842b88220
33,169
[ -1 ]
33,170
prompt-data-alt.lsp
rwoldford_Quail/source/views/views-data/prompt-data-alt.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; prompt-data-alt.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) #| (defun choose-dataset (&optional (msg NIL)) (declare (special *current-dataset*)) (let ((menu-items (dataset-menu-items)) dataset) (when menu-items (setq dataset (second (select-from-list menu-items :prompt-text (if msg msg "Choose dataset") :item-function #'first)))) (unless dataset (setq dataset (prompt-for-dataset (if msg msg "Enter dataset")))) (if (dataset-p dataset) (setq *current-dataset* dataset)) dataset)) (defun choose-variable (&optional dataset (n 1) msg menu-items) "Choose n variables from dataset" (setq msg (or msg (if (= n 1) "Choose a variable" (format nil "Choose ~A variables" n)))) ( setq menu-items (or menu-items (if dataset (variable-menu-items dataset)))) (if menu-items (if (= n 1) (loop for res = (second (select-from-list menu-items :prompt-text msg :item-function #'first)) until res finally (return res)) (loop for result = (select-from-list menu-items :prompt-text msg :item-function #'first :selection-type :multi) when result append result into result-list and do (setq msg (format nil "Choose ~A more" (- n (length result-list)))) until (>= (length result-list) n ) finally (return (subseq (mapcar #'second result-list) 0 n)))) (loop for i from 1 to n collect (wb::prompt-user :result-type t :read-type :eval :prompt-string msg)))) (defun choose-some-variables (&optional dataset (n 1) msg menu-items) "Choose n or more variables from dataset" (setq msg (or msg (format nil "Choose ~A or more variables" n))) (setq menu-items (or menu-items (if dataset (variable-menu-items dataset)))) (if menu-items (loop for res = (select-from-list menu-items :prompt-text msg :item-function #'first :selection-type :multi) when res append res into result and do (setq msg (format nil "Choose ~A or more" (- n (length result)))) until (>= (length result) n) finally (return (mapcar #'second result))) (loop with v = t until (and (>= (length var) n) (null v)) do (setq v (wb::prompt-user :result-type t :read-type :eval :prompt-string msg)) when v collect v into var finally (return var)))) |# (defun get-data-inits-2 (&key (data :prompt) (x :prompt) (y :prompt) &allow-other-keys) "Keyword argument DATA should be a dataset and X and Y indices into the dataset.~ If DATA and either X or Y are :prompt (the default),~ the user is prompted to provide a dataset.~ If X or Y is :prompt the user is prompted for variables.~ If no dataset has been specified, the make-dataset-from-vars function ~ is used to build a dataset from X and Y, and X and Y becomes the first ~ and second indices into the dataset obtained by applying the ~ list-variates function to the dataset." (when (or (eq data :prompt) (null data) (eq x :prompt) (eq y :prompt)) (if (and (or (eq data :prompt) (null data)) (or (eq x :prompt) (eq y :prompt))) (setq data (choose-dataset))) (cond ((and (eq x :prompt) (eq y :prompt)) (multiple-value-setq (x y) (values-list (select-xy-variables data :prompt-text "Choose X and Y")))) ((eq x :prompt) (setq x (choose-variable data 1 "Choose X"))) ((eq y :prompt) (setq y (choose-variable data 1 "Choose Y"))) ) (when (not (dataset-p data)) (setq data (make-dataset-from-vars x y)) (if (dataset-p data) (multiple-value-setq (x y) (values-list (list-variates data))))) (list :data data :x x :y y))) (defun get-data-inits-3 (&key (data :prompt) (x :prompt) (y :prompt) (z :prompt) &allow-other-keys) "Keyword argument DATA should be a dataset and X,Y and Z indices into the dataset.~ If DATA and either X,Y or X are :prompt (the default),~ the user is prompted to provide a dataset.~ If X is :prompt the user is prompted for an X variable.~ If Y is :prompt the user is prompted for a Y variable.~ If Z is :prompt the user is prompted for a Z variable.~ If no dataset has been specified, the make-dataset-from-vars function ~ is used to build a dataset from X,Y and Z, and X,Y and Z becomes the first ~ second and third indices into the dataset obtained by applying the ~ list-variates function to the dataset." ;;(unless x (setq x :prompt)) ;;(unless y (setq y :prompt)) ;;(unless z (setq z :prompt)) (when (or (eq data :prompt) (null data) (eq x :prompt) (eq y :prompt) (eq z :prompt)) (if (and (or (eq data :prompt) (null data)) (or (eq x :prompt) (eq y :prompt) (eq z :prompt))) (setq data (choose-dataset))) (if (or (eq x :prompt) (eq y :prompt) (eq z :prompt)) (multiple-value-setq (x y z) (values-list (select-xyz-variables data :prompt-text "Choose X,Y,Z")))) (when (not (dataset-p data)) (setq data (make-dataset-from-vars x y z)) (if (dataset-p data) (multiple-value-setq (x y z) (values-list (list-variates data))))) (list :data data :x x :y y :z z))) (defun get-data-inits-xy (&key (data :prompt) (x-vars :prompt) (y-vars :prompt) &allow-other-keys) "Keyword argument DATA should be a dataset and keyword ~ arguments X-vars and Y-vars lists of indices into the dataset.~ If DATA and X-vars or Y-vars are :prompt (the default),~ the user is prompted to provide a dataset.~ If X-vars is :prompt the user is prompted for X variables.~ If Y-vars is :prompt the user is prompted for Y variables.~ If no dataset has been specified, the make-dataset-from-vars ~ function is used to build a dataset from X-vars and Y-vars, ~ and X-vars and Y-vars become ~ lists of indices into the dataset. " (when (or (eq data :prompt) (null data) (eq x-vars :prompt) (eq y-vars :prompt)) (if (and (or (eq data :prompt) (null data)) (or (eq x-vars :prompt) (eq y-vars :prompt))) (setq data (choose-dataset))) (cond ((and (eq x-vars :prompt) (eq y-vars :prompt)) (multiple-value-setq (x-vars y-vars) (values-list (select-xy-variables data :selection-type :multi)))) ((eq x-vars :prompt) (setq x-vars (choose-some-variables data 1 "Choose one or more X variables"))) ((eq y-vars :prompt) (setq y-vars (choose-some-variables data 1 "Choose one or more Y variables")))) (when (not (dataset-p data)) (setq data (apply #'make-dataset-from-vars (append x-vars y-vars))) (when (dataset-p data) (setq x-vars (subseq (list-variates data) 0 (length x-vars))) (setq y-vars (subseq (list-variates data) (length x-vars) )))) (list :data data :x-vars x-vars :y-vars y-vars)))
8,488
Common Lisp
.l
171
38.473684
92
0.550602
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
77ec1b7b5a2e8af5035acdb214235b96bd2be0c21db21db6e4f8ea89042007f5
33,170
[ -1 ]
33,171
dataset.lsp
rwoldford_Quail/source/views/views-data/dataset.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; dataset.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(dataset list-identifiers list-variates dataset-name *datasets*))) ;; Function version below (cbh 7/94) because I needed a local method ;; for make-data-subset. Since make-data-subset uses dataset recursively, ;; dataset could not be a macro. ;; I also added a keyword arg cases to dataset, so that the cases returned ;; by list-cases on the subset are eq to the appropriate cases returned ;; by list-cases on the entire dataset. (defun dataset (data &key (identifiers NIL) (variates NIL) (name NIL) (identifier NIL) (cases NIL) (save? T) (case-class 'simple-case-object)) "This function provides a uniform facility for identifying a given data ~ structure as a dataset. ~ (:required ~ (:arg data The object to be regarded as a dataset. Usually an array, ~ or possibly a list.)) ~ (:key ~ (:arg identifiers NIL A list of strings to be used to identify the cases ~ in the dataset.) ~ (:arg variates NIL A list of strings to be used to identify the variates ~ in the dataset.) ~ (:arg cases NIL A list of simple case objects to be used for the dataset.) ~ (:arg name NIL A string used to name the dataset.) (:arg save? T A non nil value causes a named dataset to be added to *datasets*.)) ~ (:see-also list-identifiers list-variates list-cases dataset-name *datasets*)" (when data (unless (dataset-p data) (defmethod dataset-p ((d (eql data))) T)) (setq identifiers (or identifiers (loop for c in cases collect (identifier-of c)) (list-identifiers data))) (setq variates (or variates (list-variates data))) (when (and variates (not (eq variates (list-variates data)))) (defmethod list-variates ((d (eql data))) variates) ) (if (and (null cases) identifiers) (setq cases (loop for lab in identifiers as x in (list-cases data) collect (make-instance case-class :identifier (or lab (identifier-of x)) :parent-dataset data :case-vars variates :case-data x)))) (when cases (defmethod list-cases ((d (eql data))) cases)) (defmethod make-data-subset ((d (eql data)) case-list &key name identifier save? &allow-other-keys) (if case-list (let* ((case-data (if (typep (car case-list) 'simple-case-object) (mapcar #'case-data-of case-list) case-list)) (subset (or (call-next-method data case-data :name name) case-list)) (ans (dataset subset :variates variates :save? save? :name name :identifier identifier :cases case-list))) (defmethod parent-dataset-of((b (eql ans))) d) ans))) (if (stringp name) (defmethod dataset-name ((d (eql data))) name)) (setq identifier (or identifier name)) (if identifier (defmethod identifier-of ((d (eql data))) identifier)) (if save? (push data *datasets*)) data))
4,130
Common Lisp
.l
95
34.063158
131
0.54424
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
1925a77318e652b050e871f04d81280a0432b063e8a19db89b248b03791af080
33,171
[ -1 ]
33,172
data-list-test.lsp
rwoldford_Quail/source/views/views-data/data-list-test.lsp
(defun make-data (n) (loop for i from 1 to n collect (list (princ-to-string i) i (* i i) ))) (setq d (make-data 2)) (dataset-name d) (list-variates d) (setq c (second (list-cases d))) (identifier-of c) (value-of c 0) (value-of c '(sqrt 0)) (value-of c '(+ 0 1)) (values-of c '(0 1)) (values-of c (list (list #'sqrt 0) (list #'sqrt 0))) (values-of c '( (sqrt 0) (sqrt 0))) (setq vars (list "a" "b")) (push vars d) (value-of c "a" :vars vars) (value-of c 1 :vars vars) (value-of c '(+ "a" 1) :vars vars) (value-of c '(sqrt "a") :vars vars) (value-of c '(+ "a" "b") :vars vars) (value-of c '(+ (log "a") "b") :vars vars) (value-of c '(+ (log a) b) '(a b)) (values-of c '("a" "b") :vars vars) (values-of c '( (sqr "a") (sqr "a")) :vars vars) (value-of (second d) '(log "a") :vars vars) (value-of (cdr d) '(log "a") :vars vars) (value-of d "a" :vars vars)
919
Common Lisp
.l
28
29.428571
56
0.560834
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
19fb0c131c49652beaa79c9d34fdc213e59d747970f06fb748aa4ce1ee6e1347
33,172
[ -1 ]
33,173
mlevel-dataset.lsp
rwoldford_Quail/source/views/views-data/mlevel-dataset.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; mlevel-dataset.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(mlevel-case-object mlevel-dataset-class nest-datasets ))) ;; An mlevel dataset class is a dataset, but it has multilevel cases. ;; So, the cases are mlevel-case-objects (defclass mlevel-case-object (simple-case-object) ((sub-cases :initform NIL :initarg :sub-cases :accessor sub-cases-of) (parent-case :initform NIL :initarg :parent-case :accessor parent-case-of)) (:documentation "A structure representing a multilevel case.")) (defmethod list-variates ((self mlevel-case-object)) (let ((p (parent-case-of self))) (if p (append (case-vars-of self)) (list-variates p)) (case-vars-of self))) #| (defmethod case-val ((c mlevel-case-object) (v number) &key (default v)) (let ((case-vals (case-data-of c))) (if (or (not (integerp v)) (>= v (qk::number-of-elements case-vals))) (if (eq default :error) (quail-error "~A has no value for ~A" c v) default) (qk::eref case-vals v)))) (defmethod case-val ((self mlevel-case-object) v &key (default v)) (let ((p (parent-case-of self)) i) (cond ((and p (setq i (position v (case-vars-of p) :test #'eq-identifiers))) (case-val p i :default v)) (p (case-val p v :default v)) (t (if (eq default :error) (quail-error "~A has no value for ~A" self v) default))))) |# (defmethod value-of ((self mlevel-case-object) var &key (default :error)) (let* ((case-vals (case-data-of self)) (cv (case-vars-of self)) (v (position var cv :test #'eq-variates))) (if (or (not (integerp v)) (>= v (qk::number-of-elements case-vals))) (let* ((p (parent-case-of self)) (ans (if p (value-of p var :default :handle-error-here)))) (if (eq ans :handle-error-here) default ans)) (qk::eref case-vals v)))) (defmethod ancestor-data-p((a mlevel-case-object) (b mlevel-case-object)) (or (eq a (parent-case-of b)) (eq a (parent-dataset-of b)) (ancestor-data-p a (parent-case-of b)))) #| (defmethod contains-case-p((a mlevel-case-object) (b mlevel-case-object) &key (order? nil)) (if order? (or (eq-dataset a b) (ancestor-data-p a b)) (or (eq-dataset a b) (ancestor-data-p a b) (ancestor-data-p b a)))) (defmethod contains-data-p((a mlevel-case-object) (b mlevel-case-object) &key (order? nil)) (or (eq-dataset a b) (contains-case-p a b :order? order?))) |# (defclass mlevel-dataset-class(dataset-class) ()) ;; should be able to get the value of a level1 case from a level2 case ;; augment value-of ;; and list-variates. (defun nest-datasets(dataset sub-dataset &key test nest-sizes) (change-class dataset 'mlevel-dataset-class) (setf (list-variates sub-dataset) (append (list-variates sub-dataset) (list-variates dataset))) (cond ((numberp nest-sizes) (loop for c in (list-cases dataset) for rest-sub-cases on (list-cases sub-dataset) by #'(lambda(x) (nthcdr nest-sizes x)) for sub-cases = (subseq rest-sub-cases 0 nest-sizes) do (change-class c 'mlevel-case-object) (setf (sub-cases-of c) sub-cases) (loop for s in sub-cases do (change-class s 'mlevel-case-object) (setf (parent-case-of s) c)))) ((functionp test) (loop with c = (list-cases dataset) for sub in (list-cases sub-dataset) for parent = (find sub c :test test) when parent do (change-class parent 'mlevel-case-object) (change-class sub 'mlevel-case-object) (setf (parent-case-of sub) parent) (push sub (sub-cases-of parent)))) (t "fill this in")))
4,823
Common Lisp
.l
114
33.824561
123
0.546026
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
dfeb42e3b9b9f42ce0514b3f2efc0f8bff693f2be5273b8d96d8c290cc5cc95d
33,173
[ -1 ]
33,174
cbh-data-lists.lsp
rwoldford_Quail/source/views/views-data/cbh-data-lists.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; data-lists.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; DATASETS AS LISTS ;;; ;;; Simple datasets, consisting of a list of lists, each sublist is a "case". ;;; If the zeroth sublist is a list of identifiers, it is taken to be the variable ;;; names. ;;; If the zeroth element of each "case" is an identifier, it is taken to be the ;;; case label. ;;; ;;; (defmethod make-dataset-from-vars ((var list) &rest other-vars) (apply #'mapcar #'list var other-vars)) (defmethod dataset-p ((d list)) (and (not (null d)) (not (list-of-identifiers-p (cdr d))))) #| ;;; FLORENCE (defmethod dataset-p ((d list)) (not (null d))) |# (defmethod eq-dataset ((d1 list) (d2 list)) (or (eq d1 d2) (and (= (length d1) (length d2)) (every #'eq-dataset d1 d2)))) (defmethod dataset-intersection ((d1 list) (d2 list)) (cond ((member d1 d2 :test #'eq-dataset) d1) ((member d2 d1 :test #'eq-dataset) d2) ((intersection d1 d2 :test #'eq-dataset)))) #| (defmethod list-cases ((d list)) (if (listp (car d)) ;; d could be single case (if (list-of-identifiers-p (car d)) (cdr d) d) (list d))) ;;; FLORENCE (defmethod list-cases ((d list)) (if (dataset-p (car d)) d (list d))) |# (defmethod list-cases ((d list)) ;;CHANGE oct 93 ch (cond ((dataset-p (car d)) d) ((list-of-identifiers-p (car d)) (cdr d)) (t (list d)))) (defmethod extract-case ((d list) (index integer)) (elt (list-cases d) index)) #| FLORENCE (defmethod list-variates ((d list)) (if (listp (car d)) (loop for i from 0 below (length (car d)) collect i))) |# (defmethod list-variates ((d list)) (let ((case-names? (and (listp (car d)) (every #'(lambda (e) (identifier-p (car e))) d))) (var-names? (list-of-identifiers-p (car d)))) (if var-names? (car d) (if (listp (car d)) (loop for i from 0 below (- (length (car d)) (if case-names? 1 0)) collect i))))) #| FLORENCE (defmethod value-from-index ((c list) (v number) &key (default v)) (if (or (not (integerp v)) (>= v (length c))) (if (eq default :error) (quail-error "~A has no value for ~A" c v) default) (elt c v))) |# (defmethod value-from-index ((c list) (v number) &key (default v)) (let ((case-vals (if (identifier-p (car c)) (cdr c) c))) (if (or (not (integerp v)) (>= v (length case-vals))) (if (eq default :error) (quail-error "~A has no value for ~A" c v) default) (elt case-vals v)))) ;;; FLORENCE ... the following method is removed. (defmethod identifier-of ((c list)) (if (identifier-p (car c)) (car c) ))
3,600
Common Lisp
.l
105
28.8
92
0.503051
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d7f3a38fd68fe481c1bf617eca440e3555feab2d8c6d442e174e80e8db253968
33,174
[ -1 ]
33,175
prompt-data.lsp
rwoldford_Quail/source/views/views-data/prompt-data.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; prompt-data.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-dataset-from-vars prompt-for-dataset dataset-menu-items variable-menu-items choose-dataset choose-batches choose-variable choose-some-variables get-dataset-init get-data-inits get-batch-inits get-data-inits-1 get-data-inits-2 get-data-inits-3 get-barchart-inits get-data-inits-xy get-data-inits-2lists get-data-inits-3lists ))) (defun prompt-for-dataset (&optional (msg "Enter dataset" )) (let ((d (wb::prompt-user :result-type t :prompt-string msg :read-type :eval))) (if (dataset-p d) d nil))) (defun dataset-menu-items () (if *datasets* (append (list (list "A new one?" nil)) (loop with name with dset for d in *datasets* do (if (and (consp d) (stringp (car d))) (setq name (car d) dset (cdr d)) (setq name (dataset-name d) dset d)) when name collect (list name dset))))) (defun variable-menu-items (dataset) (loop for v in (list-variates dataset) for v-str = (variate-string-of v) collect (list v-str v))) (defun choose-dataset (&optional (msg NIL)) (declare (special *current-dataset* *saved-selections*)) (let ((menu-items (append (dataset-menu-items) *saved-selections*)) dataset) (when menu-items (setq dataset (cadar (wb:prompt-for-items menu-items :prompt-text (if msg msg "Choose dataset") :item-function #'first)))) (unless dataset (setq dataset (prompt-for-dataset (if msg msg "Enter dataset")))) (if (dataset-p dataset) (setq *current-dataset* dataset)) dataset)) (defun choose-batches (&optional dataset (msg "Choose one or more variables to form batches")) "Choose batches from dataset" (choose-some-variables dataset 1 msg )) (defun choose-variable (&optional dataset (n 1) msg menu-items) "Choose n variables from dataset" (setq msg (or msg (if (= n 1) "Choose a variable" (format nil "Choose ~A variables" n)))) ( setq menu-items (or menu-items (if dataset (variable-menu-items dataset)))) (if menu-items (if (= n 1) (loop for res = (cadar (wb:prompt-for-items menu-items :prompt-text msg :item-function #'first)) until res finally (return res)) (loop for result = (reverse (wb:prompt-for-items menu-items :prompt-text msg :item-function #'first :selection-type :disjoint)) when result append result into result-list and do (setq msg (format nil "Choose ~A more" (- n (length result-list)))) until (>= (length result-list) n ) finally (return (subseq (mapcar #'second result-list) 0 n)))) (loop for i from 1 to n collect (wb::prompt-user :result-type t :read-type :eval :prompt-string msg)))) (defun choose-some-variables (&optional dataset (n 1) msg menu-items) "Choose n or more variables from dataset" (setq msg (or msg (format nil "Choose ~A or more variables" n))) (setq menu-items (or menu-items (if dataset (variable-menu-items dataset)))) (if menu-items (loop for res = (reverse (wb:prompt-for-items menu-items :prompt-text msg :item-function #'first :selection-type :disjoint)) when res append res into result and do (setq msg (format nil "Choose ~A or more" (- n (length result)))) until (>= (length result) n) finally (return (mapcar #'second result))) (loop with v = t until (and (>= (length var) n) (null v)) do (setq v (wb::prompt-user :result-type t :read-type :eval :prompt-string msg)) when v collect v into var finally (return var)))) (defun get-dataset-init (&key (data :prompt) &allow-other-keys) "Keyword argument DATA should be a dataset if provided.~ If DATA is :prompt (the default),~ the user is prompted to provide a dataset." (if (eq data :prompt) (list :data (choose-dataset) ))) (defun get-data-inits (&key nvars (min-nvars 1) (data :prompt) (vars :prompt) &allow-other-keys) "Keyword argument DATA should be a dataset and keyword ~ argument VARS a list of indices into the dataset.~ If both DATA and VARS are :prompt (the default),~ the user is prompted to provide a dataset.~ If VARS is :prompt and keyword argument NVARS is integer ~ (default nil) the user is prompted for NVARS variables.~ If VARS is :prompt and NVARS is non-integer the user is prompted ~ for at least MIN-NVARS variables (default 1).~ If no dataset has been specified, the make-dataset-from-vars ~ function is used to build a dataset from VARS, and VARS becomes ~ a list of indices into the dataset obtained by applying the ~ list-variates function to the dataset. " ;;(unless vars (setq vars :prompt)) (when (or (eq data :prompt) (null data) (eq vars :prompt)) (if (and (or (eq data :prompt) (null data)) (eq vars :prompt)) (setq data (choose-dataset))) (when (eq vars :prompt) (setq vars (if (integerp nvars) (choose-variable data nvars) (choose-some-variables data min-nvars)))) (when (not (dataset-p data)) (setq data (apply #'make-dataset-from-vars vars)) (if (dataset-p data) (setq vars (list-variates data)))) (list :data data :vars vars))) (defun get-data-inits-1 (&key (data :prompt) (var :prompt) vars &allow-other-keys) "Keyword argument DATA should be a dataset and ~ keyword argument VAR an index into the dataset.~ If both DATA and VAR are :prompt, the user is prompted to provide a dataset.~ If VAR is :prompt (the default) the user is prompted for a variable.~ If no dataset has been specified, the make-dataset-from-vars ~ function is used to build a dataset from VAR, and VAR becomes ~ the first index into the dataset obtained by applying the ~ list-variates function to the dataset." (when (or (eq data :prompt) (null data) (eq var :prompt)) (if (and vars (eq var :prompt)) (setq var (or (first vars) :prompt))) (if (and (or (eq data :prompt) (null data)) (eq var :prompt)) (setq data (choose-dataset))) (if (eq var :prompt) (setq var (choose-variable data 1 ))) (when (not (dataset-p data)) (setq data (make-dataset-from-vars var)) (if (dataset-p data) (setq var (car (list-variates data))))) (list :data data :var var))) (defun get-data-inits-2 (&key (data :prompt) vars (x :prompt) (y :prompt) &allow-other-keys) "Keyword argument DATA should be a dataset and X and Y indices into the dataset.~ If DATA and either X or Y are :prompt (the default),~ the user is prompted to provide a dataset.~ If X or Y is :prompt the user is prompted for variables.~ If no dataset has been specified, the make-dataset-from-vars function ~ is used to build a dataset from X and Y, and X and Y becomes the first ~ and second indices into the dataset obtained by applying the ~ list-variates function to the dataset." (when (or (eq data :prompt) (null data) (eq x :prompt) (eq y :prompt)) (when vars (if (eq x :prompt) (setq x (or (car vars) :prompt))) (if (eq y :prompt) (setq y (or (cadr vars) :prompt)))) (if (and (or (eq data :prompt) (null data)) (or (eq x :prompt) (eq y :prompt))) (setq data (choose-dataset))) (cond ((and (eq x :prompt) (eq y :prompt)) (multiple-value-setq (x y) (values-list (choose-variable data 2 "Choose two")))) ((eq x :prompt) (setq x (choose-variable data 1 "Choose X"))) ((eq y :prompt) (setq y (choose-variable data 1 "Choose Y"))) ) (when (not (dataset-p data)) (setq data (make-dataset-from-vars x y)) (if (dataset-p data) (multiple-value-setq (x y) (values-list (list-variates data))))) (list :data data :x x :y y))) (defun get-data-inits-3 (&key (data :prompt) (x :prompt) (y :prompt) (z :prompt) vars &allow-other-keys) "Keyword argument DATA should be a dataset and X,Y and Z indices into the dataset.~ If DATA and either X,Y or X are :prompt (the default),~ the user is prompted to provide a dataset.~ If X is :prompt the user is prompted for an X variable.~ If Y is :prompt the user is prompted for a Y variable.~ If Z is :prompt the user is prompted for a Z variable.~ If no dataset has been specified, the make-dataset-from-vars function ~ is used to build a dataset from X,Y and Z, and X,Y and Z becomes the first ~ second and third indices into the dataset obtained by applying the ~ list-variates function to the dataset." ;;(unless x (setq x :prompt)) ;;(unless y (setq y :prompt)) ;;(unless z (setq z :prompt)) (when (or (eq data :prompt) (null data) (eq x :prompt) (eq y :prompt) (eq z :prompt)) (when vars (if (eq x :prompt) (setq x (or (car vars) :prompt))) (if (eq y :prompt) (setq y (or (cadr vars) :prompt))) (if (eq z :prompt) (setq z (or (caddr vars) :prompt)))) (if (and (or (eq data :prompt) (null data)) (or (eq x :prompt) (eq y :prompt) (eq z :prompt))) (setq data (choose-dataset))) (if (or (eq x :prompt) (eq y :prompt) (eq z :prompt)) (multiple-value-setq (x y z) (values-list (choose-variable data 3 "Choose 3")))) (when (not (dataset-p data)) (setq data (make-dataset-from-vars x y z)) (if (dataset-p data) (multiple-value-setq (x y z) (values-list (list-variates data))))) (list :data data :x x :y y :z z))) (defun get-barchart-inits (&key (data :prompt) (by :prompt) batches &allow-other-keys) "Keyword argument DATA should be a dataset and ~ keyword argument by is used to form batches from DATA,~ using the function get-batches. If by is :prompt the user is prompted for a value. ~ If in addition DATA is :prompt or nil, the user is prompted for a value. " (if batches (list :data (if (eq data :prompt) nil data) :by nil :batches batches) (when (eq by :prompt) (if (or (eq data :prompt) (null data)) (setq data (choose-dataset))) (setq by (choose-some-variables data 1 "Choose one or more by variables" (cons (list "Bar per case" #'list-cases) (variable-menu-items data)))) (if (member #'list-cases by) (setq batches #'list-cases by nil)) (if (eq 1 (length by)) (setq by (car by))) (list :data (if (eq data :prompt) nil data) :by by :batches batches)))) (defun get-batch-inits (&key (data :prompt) (by :prompt) batches &allow-other-keys) "Keyword argument DATA should be a dataset and ~ keyword argument by is used to form batches from DATA,~ using the function get-batches. If by is :prompt the user is prompted for a value. ~ If in addition DATA is :prompt or nil, the user is prompted for a value. " (if batches (list :data (if (eq data :prompt) nil data) :by nil :batches batches) (when (eq by :prompt) (if (or (eq data :prompt) (null data)) (setq data (choose-dataset))) (setq by (choose-some-variables data 1 "Choose one or more by variables" )) (if (eq 1 (length by)) (setq by (car by))) (list :data (if (eq data :prompt) nil data) :by by :batches batches)))) (defun get-data-inits-xy (&key vars (data :prompt) (x-vars :prompt) (y-vars :prompt) &allow-other-keys) "Keyword argument DATA should be a dataset and keyword ~ arguments X-vars and Y-vars lists of indices into the dataset.~ If DATA and X-vars or Y-vars are :prompt (the default),~ the user is prompted to provide a dataset.~ If X-vars is :prompt the user is prompted for X variables.~ If Y-vars is :prompt the user is prompted for Y variables.~ If no dataset has been specified, the make-dataset-from-vars ~ function is used to build a dataset from X-vars and Y-vars, ~ and X-vars and Y-vars become ~ lists of indices into the dataset. " (when (or (eq data :prompt) (null data) (eq x-vars :prompt) (eq y-vars :prompt)) (when vars (if (eq x-vars :prompt) (setq x-vars (or (first vars) :prompt))) (if (eq y-vars :prompt) (setq y-vars (or (second vars) :prompt)))) (if (and (or (eq data :prompt) (null data)) (or (eq x-vars :prompt) (eq y-vars :prompt))) (setq data (choose-dataset))) (when (eq x-vars :prompt) (setq x-vars (choose-some-variables data 1 "Choose one or more X variables"))) (when (eq y-vars :prompt) (setq y-vars (choose-some-variables data 1 "Choose one or more Y variables"))) (when (not (dataset-p data)) (setq data (apply #'make-dataset-from-vars (append x-vars y-vars))) (when (dataset-p data) (setq x-vars (subseq (list-variates data) 0 (length x-vars))) (setq y-vars (subseq (list-variates data) (length x-vars) )))) (list :data data :x-vars x-vars :y-vars y-vars))) (defun get-data-inits-2lists (&key (min-nvars 2) (data :prompt) (x :prompt) (y :prompt) &allow-other-keys) "Keyword argument DATA should be a dataset and keyword ~ arguments x and y lists of indices into the dataset.~ If DATA and x or y are :prompt (the default),~ the user is prompted to provide a dataset.~ If x is :prompt the user is prompted for X variables.~ If y is :prompt the user is prompted for Y variables.~ If no dataset has been specified, the make-dataset-from-vars ~ function is used to build a dataset from x and y, ~ and x and y become ~ lists of indices into the dataset.~ x and y should be the same length, at least min-nvars" (when (or (eq data :prompt) (null data) (eq x :prompt) (eq y :prompt)) (if (and (or (eq data :prompt) (null data)) (or (eq x :prompt) (eq y :prompt))) (setq data (choose-dataset))) (when (eq x :prompt) (setq x (choose-some-variables data min-nvars (format nil "Choose ~S or more X variables" min-nvars)))) (when (eq y :prompt) (setq y (if (and (listp x) (>= (length x) min-nvars)) (choose-variable data (length x) (format nil "Choose ~S Y variables" (length x))) (choose-some-variables data min-nvars (format nil "Choose ~S or more Y variables" min-nvars)) ))) (when (not (dataset-p data)) (setq data (apply #'make-dataset-from-vars (append x y))) (when (dataset-p data) (setq x (subseq (list-variates data) 0 (length x))) (setq y (subseq (list-variates data) (length x) )))) (list :data data :x x :y y))) (defun get-data-inits-3lists (&key (min-nvars 2) (data :prompt) (x :prompt) (y :prompt) (z :prompt) &allow-other-keys) "Keyword argument DATA should be a dataset and keyword ~ arguments x y and z lists of indices into the dataset.~ If DATA and x or y or z are :prompt (the default),~ the user is prompted to provide a dataset.~ If x is :prompt the user is prompted for X variables.~ If y is :prompt the user is prompted for Y variables.~ If z is :prompt the user is prompted for Z variables.~ If no dataset has been specified, the make-dataset-from-vars ~ function is used to build a dataset from x y and z, ~ and x y and z become ~ lists of indices into the dataset.~ x y and z should be the same length, at least min-nvars" (when (or (eq data :prompt) (null data) (eq x :prompt) (eq y :prompt) (eq z :prompt)) (if (and (or (eq data :prompt) (null data)) (or (eq x :prompt) (eq y :prompt))) (setq data (choose-dataset))) (when (eq x :prompt) (setq x (choose-some-variables data min-nvars (format nil "Choose ~S or more X variables" min-nvars)))) (when (eq y :prompt) (setq y (if (and (listp x) (>= (length x) min-nvars)) (choose-variable data (length x) (format nil "Choose ~S Y variables" (length x))) (choose-some-variables data min-nvars (format nil "Choose ~S or more Y variables" min-nvars))))) (when (eq z :prompt) (setq z (cond ((and (listp x) (>= (length x) min-nvars)) (choose-variable data (length x) (format nil "Choose ~S Z variables" (length x)))) ((and (listp y) (>= (length y) min-nvars)) (choose-variable data (length y) (format nil "Choose ~S Z variables" (length y)))) (t (choose-some-variables data min-nvars (format nil "Choose ~S or more Z variables" min-nvars)))))) (when (not (dataset-p data)) (setq data (apply #'make-dataset-from-vars (append x y z))) (when (dataset-p data) (setq x (subseq (list-variates data) 0 (length x))) (setq y (subseq (list-variates data) (length x) (length y))) (setq z (subseq (list-variates data) (+ (length x) (length y)))))) (list :data data :x x :y y :z z)))
19,707
Common Lisp
.l
397
38.770781
111
0.572478
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ec32847c8c9be71eff69cfe983f5cbf253801ddb752d58ae352a43f4e7deadd7
33,175
[ -1 ]
33,176
angled-brush.lsp
rwoldford_Quail/source/views/views-mixins/angled-brush.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; angled-brush.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1994 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(angled-brush set-brush-angle rotate-brush reangle-brush))) ;;---------------------------------------------------------------------------------- (defclass angled-brush (brush) ((angle :allocation :class :accessor brush-angle :initform 0) (brush-cache-pars :allocation :class :accessor brush-cache-pars :initform (make-list 6)) )) (defgeneric set-brush-angle (brush angle) (:documentation "Sets angle of brush to angle.")) (defgeneric reangle-brush (brushable-view-mixin &key viewport angle) (:documentation "Reangles brush on viewport.~ If angle is nil the user specifies an angle~ with the mouse")) (defgeneric rotate-brush (brushable-view-mixin &key viewport angle) (:documentation "Rotates brush by angle.")) (defmethod brush-angle ((self brush)) 0) (defmethod initialize-instance :after ((self angled-brush) &key ) (if (zerop (brush-angle self)) (change-class self 'brush) (set-brush-cache-pars self))) (defmethod set-brush-cache-pars ((self angled-brush)) (let* ((a (/ (brush-angle self) 180.0) ) (c (cos a)) (s (sin a)) (w (brush-width self)) (h (brush-height self)) (pars (brush-cache-pars self))) (setf (car pars) (round (* w c))) (setf (second pars) (round (* w s))) (setf (third pars) (round (* h c))) (setf (fourth pars) (round (* h s))) (setf (fifth pars) c) (setf (sixth pars) s))) (defmethod contains-p ((self angled-brush) region) (if (zerop (brush-angle self)) (call-next-method) (destructuring-bind (wc ws hc hs c s) (brush-cache-pars self) (declare (ignore wc ws hc hs)) (multiple-value-bind (l r b tp) (bounds-of region) (let* ((x (brush-x self)) (y (brush-y self)) (w (brush-width self)) (h (brush-height self)) db dr) (labels ((dbf(l b) (abs (setq db (+ (* s (- x l)) (* c (- b y)))))) (dtf() (abs (- db h))) (drf(l b) (abs (setq dr (+ (* c (- x l)) (* s (- y b)))))) (dlf() (abs (- dr w))) (inside(l b) (and (<= (dbf l b) h) (<= (dtf) h) (<= (drf l b) w) (<= (dlf) w)))) (when (and (inside l b) (inside r tp) (inside l tp) (inside r b)) region))))))) (defmethod intersects-p ((self angled-brush) region) (if (zerop (brush-angle self)) (call-next-method) (or (contains-p self region) (destructuring-bind (wc ws hc hs c s) (brush-cache-pars self) (declare (ignore c s)) (let* ((x (brush-x self)) (y (brush-y self)) (x3 (- x wc)) (y3 (- y ws)) (x1 (- x hs)) (y1 (+ y hc)) (x2 (- x1 wc)) (y2 (- y1 ws)) ) (multiple-value-bind (l r b tp) (bounds-of region) (or (line-segment-intersectp l b r b x y x1 y1) (line-segment-intersectp l b r b x2 y2 x1 y1) (line-segment-intersectp l b r b x2 y2 x3 y3) (line-segment-intersectp l b r b x y x3 y3) (line-segment-intersectp r b r tp x y x1 y1) (line-segment-intersectp r b r tp x2 y2 x1 y1) (line-segment-intersectp r b r tp x2 y2 x3 y3) (line-segment-intersectp r b r tp x y x3 y3) ;(line-segment-intersectp t tp l tp x y x1 y1) ;(line-segment-intersectp t tp l tp x2 y2 x1 y1) ;;; 08MAR2022 gwb ;(line-segment-intersectp t tp l tp x2 y2 x3 y3) ;(line-segment-intersectp t tp l tp x y x3 y3) (line-segment-intersectp r tp l tp x y x1 y1) (line-segment-intersectp r tp l tp x2 y2 x1 y1) (line-segment-intersectp r tp l tp x2 y2 x3 y3) (line-segment-intersectp r tp l tp x y x3 y3) (line-segment-intersectp l tp l b x y x1 y1) (line-segment-intersectp l tp l b x2 y2 x1 y1) (line-segment-intersectp l tp l b x2 y2 x3 y3) (line-segment-intersectp l tp l b x y x3 y3)))))))) (defmethod shape-brush ((self angled-brush) width height) (setf (brush-width self) width) (setf (brush-height self) height) (set-brush-cache-pars self) self) (defmethod set-brush-angle ((self brush) angle) (unless (zerop angle) (change-class self 'angled-brush) (setf (brush-angle self) angle) (set-brush-cache-pars self))) (defmethod set-brush-angle ((self angled-brush) angle) (setf (brush-angle self) angle) (set-brush-cache-pars self)) (defmethod locate-brush((self angled-brush) region) (multiple-value-bind (l r b tp) (bounds-of region) (setf (brush-x self) r) (setf (brush-width self) (- r l)) (setf (brush-y self) b) (setf (brush-height self) (- tp b))) (set-brush-cache-pars self)) (defmethod default-brush-shape ((Self angled-brush)) (shape-brush self *default-brush-width* *default-brush-height*) (set-brush-angle self 0)) (defmethod xor-draw-brush-at-xy ((self angled-brush) viewport x y) (destructuring-bind (wc ws hc hs c s) (brush-cache-pars self) (declare (ignore c s)) (let* ((bw (window-of viewport)) (x3 (- x wc)) (y3 (- y ws)) (x1 (- x hs)) (y1 (+ y hc)) (x2 (- x1 wc)) (y2 (- y1 ws)) ) (wb:canvas-move-to bw x y) (wb:canvas-draw-to bw x1 y1 :operation :boole-xor) (wb:canvas-draw-to bw x2 y2 :operation :boole-xor) (wb:canvas-draw-to bw x3 y3 :operation :boole-xor) (wb:canvas-draw-to bw x y :operation :boole-xor)))) (defmethod draw-brush ((self angled-brush) viewport &optional (x (brush-x self)) (y (brush-y self))) (xor-draw-brush-at-xy self viewport x y) (setf (brush-x self) x) (setf (brush-y self) y)) (defmethod move-brush ((self angled-brush ) viewport &optional x y ) (let* ((w (window-of viewport)) (old-x (brush-x self)) (old-y (brush-y self))) (setq x (or x (wb:mouse-x w))) (setq y (or y (wb:mouse-y w))) (unless (and (= x old-x) (= y old-y )) (xor-draw-brush-at-xy self viewport old-x old-y) (xor-draw-brush-at-xy self viewport x y) (setf (brush-x self) x) (setf (brush-y self) y)))) (defmethod rotate-brush ((self brushable-view-mixin) &key viewport angle) (let ((brush (brush-of self)) ) (change-class brush 'angled-brush) (if angle (set-brush-angle brush angle) (let* ((w (window-of viewport))) (set-brush-angle brush 0) (draw-brush brush viewport (wb:mouse-x w) (wb:mouse-y w)) (loop with start-time = (get-universal-time) with wait-time = 1/1200 until (or (>= (- (get-universal-time) start-time) wait-time) (wb:mouse-down-p))) (loop while (wb:mouse-down-p) do (draw-brush brush viewport) (if (> (wb:mouse-y w) (brush-y brush)) (set-brush-angle brush (+ (brush-angle brush) 2)) (set-brush-angle brush (- (brush-angle brush) 2))) (draw-brush brush viewport (wb:mouse-x w) (wb:mouse-y w)) ) (draw-brush brush viewport) )))) ;; Already defined at line 143 in identical code - chose the earlier one GWB 07SEP2023 ;(defmethod set-brush-angle ((self angled-brush) angle) ; (setf (brush-angle self) angle) ; (set-brush-cache-pars self)) (defmethod reshape-brush ((self angled-brush) ;brushable-view-mixin) 07SEP2023 &key viewport width height) (let ((brush (brush-of self)) ) (unless (and width height ) (set-brush-angle brush 0) (let (ignore) (declare (ignorable ignore)) (multiple-value-setq (ignore ignore width height) (wb:select-rectangle :canvas (window-of viewport) :width (brush-width brush) :height (brush-height brush))) )) (shape-brush brush width height) )) (defmethod reangle-brush ((self brushable-view-mixin ) &key viewport angle) (let ((brush (brush-of self))) (if angle (set-brush-angle brush angle) (rotate-brush self :viewport viewport)) )) (defmethod get-brush-menu-items ((self brushable-view-mixin)) '(("Brush" nil "" :sub-items ( ("Shape Brush" (reshape-brush :viewport) ) ("Angle Brush" (reangle-brush :viewport) ) )) ("-" nil))) ;; this version allows brush to be angled
9,662
Common Lisp
.l
214
35.415888
125
0.542388
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ed843b61ea346d1912e235362b7d4d096ee76d955886757de8b8f6bba563dc23
33,176
[ -1 ]
33,177
lines-mixin.lsp
rwoldford_Quail/source/views/views-mixins/lines-mixin.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; lines-mixin.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( basic-lines-mixin single-style-lines-mixin multi-style-lines-mixin lines-mixin draw-lines lines-coords-for-viewport ))) (defgeneric compute-lines-coords-for-viewport (self vp )) ;; the mixin viewport-coords-cache-mixin added on 4-20-95. If this ;; is removed also remove other changes below: see *** (defclass basic-lines-mixin (viewport-coords-cache-mixin linkable-mixin) ((middle-menu :allocation :class :initform nil) (style-keys :initform '(:dashing :width :color) :allocation :class) (bounding-region :initarg :plot-region :initform nil :accessor bounding-region-of :documentation "A region in the local coordinates of view used to define its bounds") (clip-draw? :initform t :initarg :clip-draw? :accessor clip-draw-p) (lines-coords :initarg :lines-coords :initform nil :accessor lines-coords-of)) (:default-initargs :dashing nil :width 1 :color *default-curve-color* :linkable? nil :viewport-compute-method #'compute-lines-coords-for-viewport)) (defclass multi-style-lines-mixin (multiple-draw-style-mixin basic-lines-mixin) ()) (defclass lines-mixin ( basic-lines-mixin) ()) ;; the default mixin (defgeneric lines-coords-for-viewport (lines-mixin viewport) (:documentation "Returns the viewport coordinates of line segments~ as a list of cons pairs")) (defgeneric draw-lines (lines-mixin viewport &key &allow-other-keys) (:documentation "Draws the connected line segments in viewport")) ;;------------------------------------------------------------------------------------ ;; *** this method needed for added mixin viewport-coords-cache-mixin (defmethod compute-lines-coords-for-viewport ((self basic-lines-mixin) vp ) (let ( (c-list (lines-coords-of self)) (map (select-map-to-viewport self vp) ) ox oy sx sy) (setq ox (x-shift map) sx (x-scale map) oy (y-shift map) sy (y-scale map)) (loop for c in c-list collect (if (and (numberp (car c)) (numberp (cadr c)) ) (cons (truncate (+ ox (* sx (car c)))) (truncate (+ oy (* sy (cadr c))))))))) ;; *** this method needed for added mixin viewport-coords-cache-mixin (defmethod (setf lines-coords-of) :after (new (self basic-lines-mixin)) (declare (ignore new)) (remove-viewport-coords self)) ;; *** this method needed for added mixin viewport-coords-cache-mixin (defmethod lines-coords-for-viewport ((self basic-lines-mixin) vp ) (viewport-coords-of self :viewport vp)) (defmethod erase-view ((self basic-lines-mixin) &key viewport delta-width ) (unless delta-width (setq delta-width (if (draw-style self :highlight?) (highlight-delta self) (erase-delta self)))) (with-exposed-viewports self viewport vp (draw-lines self vp :operation :boole-andc1 :delta-width delta-width))) (defmethod invert-view ((self basic-lines-mixin) &key viewport (delta-width 1)) (with-exposed-viewports self viewport vp (draw-lines self vp :operation :boole-xor :delta-width delta-width))) (defmethod draw-view ((self basic-lines-mixin) &key viewport) (with-exposed-viewports self viewport vp (draw-lines self vp))) (defmethod erase-delta ((self basic-lines-mixin)) 0) (defmethod downlight-view ((self basic-lines-mixin) &key viewport operation) (setq operation (or operation (highlight-operation self))) (if (eql operation :boole-xor) (highlight-view self :viewport viewport :operation operation) (progn (erase-view self :viewport viewport :delta-width (highlight-delta self)) (unless (draw-style self :invisible?) (draw-view self :viewport viewport :erase? nil))))) (defmethod highlight-delta ((self basic-lines-mixin)) 0) (defmethod highlight-operation ((self basic-lines-mixin)) :default) (defun window-draw-line (x y x1 y1 bw wb-region clip? color operation width) (declare (ignore y)) (wb:with-pen-values bw color width operation (cond ((and x x1) (if clip? (wb:clipped-draw-to bw x1 y1 wb-region) (wb:canvas-draw-to bw x1 y1))) (x1 (wb:canvas-move-to bw x1 y1)) (t nil)))) (defmethod simple-draw-lines ((self basic-lines-mixin) vp &key (operation :default) (delta-width 0) (width (+ (draw-style self :width) delta-width)) (color (draw-style self :color))) (let ((coords (lines-coords-for-viewport self vp)) (bw (window-of vp)) (clip? (clip-draw-p self)) (wb-region (wb-region vp)) ;;(dashing (draw-style self :dashing)) ) (when coords (wb:with-pen-values bw color width operation (if clip? (loop for (x . y) in (cons nil coords) for (x1 . y1) in coords do (cond ((and x x1) (wb:clipped-draw-to bw x1 y1 wb-region)) (x1 (wb:canvas-move-to bw x1 y1)) (t nil))) (loop for (x . y) in (cons nil coords) for (x1 . y1) in coords do (cond ((and x x1) (wb:canvas-draw-to bw x1 y1)) (x1 (wb:canvas-move-to bw x1 y1)) (t nil)))))))) (defmethod is-brushed-p((self basic-lines-mixin) (brush brush) viewport) (or (contains-p brush viewport) (let* ((a2 (brush-x brush)) (b1 (brush-y brush)) (a1 (- a2 (brush-width brush))) (b2 (+ b1 (brush-height brush))) (coords (lines-coords-for-viewport self viewport))) (loop for (x1 . y1) in coords for (x2 . y2) in (cdr coords) thereis (and x1 x2 (or (line-segment-intersectp x1 y1 x2 y2 a1 b1 a1 b2) (line-segment-intersectp x1 y1 x2 y2 a1 b2 a2 b2) (line-segment-intersectp x1 y1 x2 y2 a2 b2 a2 b1) (line-segment-intersectp x1 y1 x2 y2 a2 b1 a1 b1))))))) (defmethod is-brushed-p((self basic-lines-mixin) (brush angled-brush) viewport) (if (zerop (brush-angle self)) (call-next-method) (or (contains-p brush viewport) (destructuring-bind (wc ws hc hs c s) (brush-cache-pars brush) (declare (ignore c s)) (let* ((x (brush-x self)) (y (brush-y self)) (x3 (- x wc)) (y3 (- y ws)) (x1 (- x hs)) (y1 (+ y hc)) (x2 (- x1 wc)) (y2 (- y1 ws)) (coords (lines-coords-for-viewport self viewport))) (if (and coords (caar coords)) (loop for (a1 . b1) in coords for (a2 . b2) in (cdr coords) thereis (and a1 a2 (or (line-segment-intersectp a1 b1 a2 b2 x y x1 y1) (line-segment-intersectp a1 b1 a2 b2 x2 y2 x1 y1) (line-segment-intersectp a1 b1 a2 b2 x2 y2 x3 y3) (line-segment-intersectp a1 b1 a2 b2 x y x3 y3)))))))))) ;;---------------------------------------------------------------------- (defun line-default-middle-items () (let ((size-change-list '(("fatter" (set-drawing-style :width :fatter :highlit? *selected-subviews-only*)) ("thinner" (set-drawing-style :width :thinner :highlit? *selected-subviews-only*)) ("prompt" (set-drawing-style :width :prompt :highlit? *selected-subviews-only*))))) (list `( "Width" nil "" :sub-items ,size-change-list)))) (defmethod style-menu-items ((self basic-lines-mixin) ) (line-default-middle-items)) ;;---------------------------------------------------------------------- (defmethod draw-lines ((self lines-mixin) viewport &key (operation :default) (delta-width 0) (width (+ (draw-style self :width) delta-width)) (color (draw-style self :color))) (simple-draw-lines self viewport :operation operation :delta-width :delta-width :width width :color color)) (defmethod highlight-view ((self lines-mixin) &key viewport (delta-width (highlight-delta self))) (with-exposed-viewports self viewport vp (draw-lines self vp :delta-width delta-width :color *default-highlight-color* :operation (highlight-operation self)))) (defmethod draw-lines ((self multi-style-lines-mixin) vp &key (operation :default) (delta-width 0 )) (let* ((styles (drawing-styles-of self)) (coords (lines-coords-for-viewport self vp)) (bw (window-of vp)) (clip? (clip-draw-p self)) (wb-region (wb-region vp)) (alpha (/ 1 (max 1 (length styles)))) (n (length coords)) ) (when coords (if (and (>= (length styles) n) (not (= n 2))) (loop for (x . y) in (cons nil coords) for (x1 y1) in coords for ds in (cons nil styles) do (if (and ds (draw-style ds :invisible)) (setq x nil)) (window-draw-line x y x1 y1 bw wb-region clip? (draw-style ds :color) operation (+ delta-width (draw-style ds :width ) ))) (loop with dx and dy for (x . y) in coords for (x1 . y1) in (cdr coords ) when (and x x1) do (wb:canvas-move-to bw x y) (setq dx (- x1 x) dy (- y1 y)) (loop for ds in styles do (window-draw-line (and (not (draw-style ds :invisible? )) x) y (incf x (* alpha dx)) (incf y (* alpha dy)) bw wb-region clip? (draw-style ds :color) operation (+ delta-width (draw-style ds :width )))))))) ) (defmethod highlight-view ((self multi-style-lines-mixin) &key viewport (delta-width (highlight-delta self))) (let* ((clip? (clip-draw-p self)) (styles (drawing-styles-of self)) (alpha (/ 1 (max 1 (length styles)))) (operation (highlight-operation self))) (with-exposed-viewports self viewport vp (let* ( (coords (lines-coords-for-viewport self vp)) (bw (window-of vp)) (wb-region (wb-region vp)) (n (length coords))) (when coords (if (and (>= (length styles) n) (not (= n 2))) (loop for (x . y) in (cons nil coords) for (x1 y1) in coords for ds in (cons nil styles) do (if (and ds (not (draw-style ds :highlight? ))) (setq x nil)) (window-draw-line x y x1 y1 bw wb-region clip? *default-highlight-color* operation (+ delta-width (draw-style ds :width )))) (loop with dx and dy for (x . y) in coords for (x1 . y1) in (cdr coords ) when (and x x1) do (wb:canvas-move-to bw x y) (setq dx (- x1 x) dy (- y1 y)) (loop for ds in styles do (window-draw-line (and (draw-style ds :highlight? ) x) y (incf x (* alpha dx)) (incf y (* alpha dy)) bw wb-region clip? *default-highlight-color* operation (+ delta-width (draw-style ds :width ))))))))))) (defmethod use-x-axis-p ((self basic-lines-mixin)) t) (defmethod use-y-axis-p ((self basic-lines-mixin)) t) (defmethod distance-to-location ((self basic-lines-mixin) viewport location) ;; computes squared euclidean distance (let* ((coords (lines-coords-for-viewport self viewport)) (locn (if (region-p location) (centre-of location) location)) (x (2d-position-x locn)) (y (2d-position-y locn)) ) (if coords (sqrt (labels ((d2 (x1 y1 x2 y2) (+ (expt ( - x1 x2) 2) (expt ( - y1 y2) 2))) (dt (x1 y1 x2 y2 x y) (let ((d12 (+ (* (- x1 x) (- x2 x)) (* (- y1 y) (- y2 y))))) (and (< d12 (d2 x1 y1 x y)) (< d12 (d2 x2 y2 x y))))) (dp (x1 y1 x2 y2 x y) (/ (abs (+ (* x (- y2 y1)) (* y (- x1 x2)) ( * x2 y1) (* y2 (- x1)))) (sqrt (d2 x1 y1 x2 y2))))) (loop for (x1 . y1) in coords for (x2 . y2) in (cdr coords) when (and x1 x2) minimize (cond ((and (= x2 x1) (= y2 y1)) (d2 x y x1 y1)) ((dt x1 y1 x2 y2 x y) (expt (dp x1 y1 x2 y2 x y) 2)) (t (min (d2 x y x1 y1) (d2 x y x2 y2))))))) 10000))) (defmethod selected-p ((self basic-lines-mixin) viewport location) ;; is view selected with mouse at location? ;; if the viewport has (and (active-viewport-p viewport) ;; (or (contains-p viewport location) (< (distance-to-location self viewport location) 10)))
14,777
Common Lisp
.l
300
36.456667
96
0.520285
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9439e86305cb0cc80947c0027dc224ddf3fc14614159d0c5d3afc9d6e77b7921
33,177
[ -1 ]
33,178
brush.lsp
rwoldford_Quail/source/views/views-mixins/brush.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; brush.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(brush shape-brush default-brush-shape draw-brush move-brush brushable-view-mixin brush-of get-brush-menu-item toggle-brushing reshape-brush drag-brush))) ;;;---------------------------------------------------------------------------------- ;; (eval-when ...) is necessary since the brush slot of brushable-view-mixin ;; is class-allocated, and hence evaluated at compile-time #| (eval-when (:compile-toplevel :load-toplevel :execute) (defclass brush () ((height :allocation :class :accessor brush-height :initform *default-brush-height*) (width :allocation :class :accessor brush-width :initform *default-brush-width*) (brush-x :accessor brush-x :initform nil ) (brush-y :accessor brush-y :initform nil) (brush-test :accessor brush-test-of :initform #'intersects-p) (brush-mode :accessor brushing-mode-of :initform :select) (drag-brushing? :accessor drag-brushing-p :initform nil))) (defun make-brush () (make-instance 'brush )) ) |# (defclass brush () ((height :allocation :class :accessor brush-height :initform *default-brush-height*) (width :allocation :class :accessor brush-width :initform *default-brush-width*) (brush-x :accessor brush-x :initform nil ) (brush-y :accessor brush-y :initform nil) (brush-test :accessor brush-test-of :initform #'is-brushed-p :initarg :brush-test) (brush-mode :accessor brushing-mode-of :initform :select) (drag-brushing? :accessor drag-brushing-p :initform nil))) (defun make-brush (&rest args) (apply #'make-instance 'brush args)) (defclass brushable-view-mixin () ((brush ;;:allocation :class :accessor brush-of :initarg :brush :initform nil))) (defclass draggable-brush-view-mixin (brushable-view-mixin) ()) (defgeneric shape-brush (brush width height) (:documentation "Shape brush using width and height")) (defgeneric locate-brush (brush region) (:documentation "Set brush location to region")) (defgeneric default-brush-shape (brush) (:documentation "Shape brush using default width and height")) (defgeneric draw-brush (brush viewport &optional x y) (:documentation "Draw brush at x,y in viewport")) (defgeneric move-brush ( brush viewport &optional x y ) (:documentation "Move brush to x,y in viewport" )) (defgeneric toggle-brushing (brushable-view-mixin &key) (:documentation "Toggle brushing on-off")) (defgeneric reshape-brush (brushable-view-mixin &key viewport width height) (:documentation "Reshape brush on viewport.~ If width or height is nil the user shapes a rectangle~ with the mouse")) (defgeneric drag-brush (brushable-view-mixin &key viewport width height) (:documentation "Drag brush on viewport")) ;;;---------------------------------------- (defmethod locate-brush((self brush) region) (multiple-value-bind (l r b tp) (bounds-of region) (setf (brush-x self) r) (setf (brush-width self) (- r l)) (setf (brush-y self) b) (setf (brush-height self) (- tp b)))) (defmethod contains-p ((self brush) region) (multiple-value-bind (l r b tp) (bounds-of region) (let* ((xmax (brush-x self)) (xmin (- xmax (brush-width self))) (ymin (brush-y self)) (ymax (+ ymin (brush-height self)))) (when (and (>= l xmin ) (<= r xmax) (>= b ymin ) (<= tp ymax)) region)))) (defmethod intersects-p ((self brush) region) (multiple-value-bind (la ra ba ta) (bounds-of region) (let* ((rb (brush-x self)) (lb (- rb (brush-width self))) (bb (brush-y self)) (tb (+ bb (brush-height self)))) (when (and (<= (max la lb) (min ra rb)) (<= (max ba bb) (min ta tb))) region)))) (defmethod shape-brush ((self brush) width height) (setf (brush-width self) width) (setf (brush-height self) height) self) (defmethod default-brush-shape ((Self brush)) (shape-brush self *default-brush-width* *default-brush-height*)) #| (defmethod draw-brush ((self brush) viewport &optional (x (brush-x self)) (y (brush-y self))) (let ((bw (window-of viewport))) (setf (brush-x self) x) (setf (brush-y self) y) (wb:canvas-draw-rectangle bw (- x (brush-width self)) x y (+ y (brush-height self)) :operation :boole-xor))) |# (defmethod draw-brush ((self brush) viewport &optional x y) (let ((bw (window-of viewport))) (if (null x) (progn (setq x (brush-x self)) (if (null x) (setq x (setf (brush-x self) (wb:mouse-x bw))))) (setf (brush-x self) x)) (if (null y) (progn (setq y (brush-y self)) (if (null y) (setq y (setf (brush-y self) (wb:mouse-y bw))))) (setf (brush-y self) y)) (wb:canvas-draw-rectangle bw (- x (brush-width self)) x y (+ y (brush-height self)) :operation :boole-xor))) (defmethod move-brush ((self brush ) viewport &optional x y ) (let* ( ;;(b (brush-bitmap self)) (w (window-of viewport)) (wid (brush-width self)) (hgt (brush-height self)) (old-x (brush-x self)) (old-y (brush-y self))) (setq x (or x (wb:mouse-x w))) (setq y (or y (wb:mouse-y w))) (unless (and (= x old-x) (= y old-y )) (wb:canvas-draw-rectangle w (- old-x wid) old-x old-y (+ old-y hgt) :operation :boole-xor) (setf (brush-x self) x) (setf (brush-y self) y) (wb:canvas-draw-rectangle w (- x wid) x y (+ y hgt) :operation :boole-xor) ))) (defmethod remake-menu :after ((self brushable-view-mixin ) (slot-name (eql 'middle-menu)) &optional middle) (setf (slot-value self 'middle-menu) (or middle (append (get-brush-menu-items self) (slot-value self 'middle-menu) )))) (defmethod default-brush-test ((self brushable-view-mixin)) #'is-brushed-p) (defmethod brush-of ((self brushable-view-mixin)) (or (slot-value self 'brush) (setf (slot-value self 'brush) (make-brush :brush-test (default-brush-test self))))) (defgeneric is-brushed-p(view brush viewport) (:documentation "Is the image of view in viewport brushed ?")) (defmethod is-brushed-p((self view) (brush brush) viewport) (contains-p brush viewport)) (defmethod get-brush-menu-items ((self brushable-view-mixin)) '(("Shape Brush" (reshape-brush :viewport) ) ("-" nil))) (defmethod update-menu-items :after ((self brushable-view-mixin) (slot-name (eql 'middle-menu))) (update-brush-menu-items self)) (defmethod update-brush-menu-items ((self brushable-view-mixin) ) nil) (defmethod get-brush-menu-items ((self draggable-brush-view-mixin)) '(("Brush" nil "" :sub-items (("BrushMode?" (toggle-brushing)) ("Shape Brush" (reshape-brush :viewport) ) ("Angle Brush" (reangle-brush :viewport) ) )) ("-" nil))) (defmethod update-brush-menu-items ((self draggable-brush-view-mixin)) (let* ((m (wb:get-menu-item (slot-value self 'middle-menu) "Brush")) (brush (brush-of self))) (wb:check-menu-item m "BrushMode?" (drag-brushing-p brush)) #| (if (drag-brushing-p brush) (progn (wb:enable-menu-item m "BrushHigh?") (wb:enable-menu-item m "Shape Brush")) (progn (wb:disable-menu-item m "BrushHigh?") (wb:disable-menu-item m "Shape Brush"))) |# )) (defmethod toggle-brushing ((self draggable-brush-view-mixin) &key) (let ((brush (brush-of self))) (setf (drag-brushing-p brush) (not (drag-brushing-p brush ))))) (defmethod brush-test-of ((self brushable-view-mixin ) ) (brush-test-of (brush-of self))) (defmethod brushing-mode-of ((self brushable-view-mixin ) ) (brushing-mode-of (brush-of self))) (defmethod reshape-brush ((self brushable-view-mixin) &key viewport width height) (let ((brush (brush-of self)) ignore) (declare (ignorable ignore)) (unless (and width height ) (multiple-value-setq (ignore ignore width height) (wb:select-rectangle :canvas (window-of viewport) :width (brush-width brush) :height (brush-height brush)))) (shape-brush brush width height) )) (defmethod collect-views-in-region ((self brushable-view-mixin ) &key viewport region) (let ((brush (brush-of self)) (test (brush-test-of self))) (if region (progn (locate-brush brush region) (loop for sv in (subviews-of self) for vis in (visible-subviews-p self) for vp = (select-viewport sv viewport) when (and vis (funcall test sv brush vp)) collect sv)) (let* ((w (window-of viewport)) (old-ang (brush-angle brush)) (old-wid (brush-width brush)) (old-hgt (brush-height brush))) (shape-brush brush *default-brush-width* *default-brush-height*) (reshape-brush self :viewport viewport) (if (typep brush 'angled-brush) (rotate-brush self :viewport viewport)) (draw-brush brush viewport (wb:mouse-x w) (wb:mouse-y w)) (loop for sv in (subviews-of self) for vis in (visible-subviews-p self) for vp = (select-viewport sv viewport) when (and vis (funcall test sv brush vp)) collect sv finally (draw-brush brush viewport) (shape-brush brush old-wid old-hgt) (set-brush-angle brush old-ang)))))) (defmethod default-left-fn ((self brushable-view-mixin ) &key viewport position) ;; select, no toggle (declare (ignore position)) (short-description self) (let ((sel (collect-views-in-region self :viewport viewport)) ) (with-update-style-cache (loop for v in *selected-views* do (set-highlight-style v nil)) (loop for v in sel do (set-highlight-style v t)) (set-selected-views sel)))) (defmethod shift-left-button-fn ((self brushable-view-mixin ) &key viewport position) (declare (ignore position)) (short-description self) (let ((new (collect-views-in-region self :viewport viewport))) (with-update-style-cache (loop for v in new do (set-highlight-style v t) (pushnew v *selected-views*))))) (defmethod shift-middle-button-fn ((self brushable-view-mixin ) &key viewport position) ;; intersection ;; turns off the parts of highlit views which are not linked to self (declare (ignore position)) (short-description self) (when *selected-views* (let* ((old-views (remove-duplicates (highlighted-views))) (sel-views (collect-views-in-region self :viewport viewport))) (loop for v in old-views do (set-highlight-style v nil :not-from sel-views :draw-links? nil)) (set-selected-views sel-views)))) (defmethod shift-right-button-fn ((self brushable-view-mixin ) &key viewport position) (declare (ignore position)) (short-description self) (when *selected-views* (let ((new (collect-views-in-region self :viewport viewport))) (with-update-style-cache (loop for v in new ;; when (any-highlight? v) do (set-highlight-style v nil) (set-selected-views (delete v *selected-views*))) *selected-views* )))) (defmethod drag-brush ((self draggable-brush-view-mixin ) &key viewport &allow-other-keys) (let ((bw (window-of viewport))) (draw-brush (brush-of self) viewport (wb:mouse-x bw) (wb:mouse-y bw)) (loop until (not (wb:mouse-down-p)) do (move-brush (brush-of self) viewport)) (draw-brush (brush-of self) viewport ))) (defmethod default-left-fn ((self draggable-brush-view-mixin) &key viewport &allow-other-keys) (if (drag-brushing-p (brush-of self)) (progn (setf (brushing-mode-of (brush-of self)) :select) (drag-brush self :viewport viewport)) (call-next-method))) (defmethod shift-left-button-fn ((self draggable-brush-view-mixin ) &key viewport &allow-other-keys) (if (drag-brushing-p (brush-of self)) (progn (setf (brushing-mode-of (brush-of self)) :union) (drag-brush self :viewport viewport)) (call-next-method))) (defmethod shift-middle-button-fn ((self draggable-brush-view-mixin ) &key viewport &allow-other-keys) (if (drag-brushing-p (brush-of self)) (progn (setf (brushing-mode-of (brush-of self)) :intersection) (drag-brush self :viewport viewport)) (call-next-method))) (defmethod shift-right-button-fn ((self draggable-brush-view-mixin ) &key viewport &allow-other-keys) (if (drag-brushing-p (brush-of self)) (progn (setf (brushing-mode-of (brush-of self)) :difference) (drag-brush self :viewport viewport)) (call-next-method)))
14,914
Common Lisp
.l
331
35.271903
105
0.579184
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c8eafb37ddc6538d5d57a9b86ae6e3f1e5054762ad6491012f05a0b3b2db2478
33,178
[ -1 ]
33,179
nother-link.lsp
rwoldford_Quail/source/views/views-mixins/nother-link.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; link.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(linkable-mixin link-views link-highlit-view unlink-views link-view unlink-view link-to-selected get-link-table fast-link2-views))) (defclass linkable-mixin () ((linked-views :initform nil :initarg :linked-views :accessor linked-views-of) (link-table :initform nil :accessor link-table-of))) (defgeneric get-link-table(view) (:documentation "Returns a link table from the hierarchy of view")) (defgeneric fast-link2-views(view1 view2 &key draw? link-table) (:documentation "Links the two views. Does not compare the viewed elements ")) ;;;---------------------------------------------------------------------------------- (defmethod link-table-of ((self view)) nil) (defmethod linked-views-of ((self view)) nil) (defmethod get-link-table((self view)) (some #'get-link-table (subviews-of self))) (defmethod get-link-table((self linkable-mixin)) (link-table-of self)) (defmethod viewed-elt-test ((self linkable-mixin)) (let ((tab (link-table-of self))) (if tab (link-table-test-of tab) (call-next-method)))) #| (defmethod set-drawing-style :after ((self linkable-mixin) &key (draw-links? t) element styles (draw? t) (erase? draw?)) (if (and (linked-views-of self) draw-links?) (let ((linked-views (linked-views-of self)) (test (viewed-elt-test self))) (if element (loop for v in linked-views do (set-drawing-style v :draw-links? nil :element element :test test :styles styles :draw? draw? :erase? erase?)) (let ((lvo (list-viewed-elements self))) (when lvo (loop for v in linked-views do (loop for vo in (cdr lvo) do (set-drawing-style v :draw-links? nil :element vo :test test :draw? nil :styles styles)) (set-drawing-style v :draw-links? nil :element (car lvo) :test test :draw? draw? :erase? erase? :styles styles)))))))) |# ;; on 2/22/95 changed code so that iteration over (list-viewed-elements self) is done ;; on the linked view if necessary. This version will be more efficient because ;; simple-style-mixins will not need to do this iteration. (defmethod set-drawing-style :after ((self linkable-mixin) &key (draw-links? t) element styles (draw? t) (erase? draw?)) (if (and (linked-views-of self) draw-links?) (let ((linked-views (linked-views-of self)) (test (viewed-elt-test self))) (if element (loop for v in linked-views do (set-drawing-style v :draw-links? nil :element element :test test :styles styles :draw? draw? :erase? erase?)) (loop for v in linked-views do (set-drawing-style v :draw-links? nil :from self :test test :draw? draw? :erase? erase? :styles styles)) )))) ;;; Added do-nothing primary FEB 02,1998 (defmethod set-highlight-style ((self linkable-mixin) hi-val &key (draw-links? t) element (draw? t) (er ase? draw?)) (declare (ignore self hi-val draw-links? element draw? erase?)) (call-next-method)) (defmethod set-highlight-style :after ((self linkable-mixin) hi-val &key (draw-links? t) element (draw? t) (erase? draw?)) (if (and (linked-views-of self) draw-links?) (let ((linked-views (linked-views-of self)) (test (viewed-elt-test self))) (if element (loop for v in linked-views do (set-highlight-style v hi-val :draw-links? nil :element element :test test :draw? draw? :erase? erase?)) (loop for v in linked-views do (set-highlight-style v hi-val :draw-links? nil :from self :test test :draw? draw? :erase? erase?)) )))) (defmethod highlight-operation ((self linkable-mixin)) :default ) ;;------------------------------------------------------------------------------------ (defun make-the-link (v1 v2) (push v1 (linked-views-of v2)) (push v2 (linked-views-of v1))) (defun break-all-links (v) (loop for link in (linked-views-of v) do (setf (linked-views-of link) (delete v (linked-views-of link)))) (setf (linked-views-of v) nil)) ;;---------------------------------------------------------------------------------------- (defun link-to-selected(view) "Links view to the selected views." (let ((selected (copy-list *selected-views* ))) (deselect-all) (apply #'link-views view selected))) (defun link-views (&rest views ) (let* ((table (or (loop for v in views thereis (and (typep v 'link-table) v)) (use-link-table))) (one-per-case (descendant-views-of-type views 'one-per-case-mixin)) (d (car one-per-case))) (when one-per-case (link-view d :draw? t :link-table table) (loop for di in (cdr one-per-case) when (eq (viewed-object-of di) (viewed-object-of d)) do (loop for a in (subviews-of d) for b in (subviews-of di) do (fast-link2-views a b :draw? t :link-table table)))) (loop for v in views when (typep v 'view) do (link-view v :draw? t :link-table table)))) (defmethod link-view ((self view) &key (draw? t) (link-table (use-link-table)) (fast? t)) (if fast? (let* ((one-per-case (descendant-views-of-type self 'one-per-case-mixin)) (d (car one-per-case))) (when one-per-case (link-view d :draw? draw? :link-table link-table :fast? nil) (loop for di in (cdr one-per-case) when (eq (viewed-object-of di) (viewed-object-of d)) do (loop for a in (subviews-of d) for b in (subviews-of di) do (fast-link2-views a b :draw? draw? :link-table link-table)))))) (loop for v in (subviews-of self) do (link-view v :draw? draw? :link-table link-table :fast? nil))) (defmethod link-view ((self linkable-mixin) &key (draw? t) (link-table (use-link-table))) (let ((my-table (link-table-of self))) (unless (and my-table (eql my-table link-table)) (if (and my-table (not (eql my-table link-table))) (unlink-view self)) (foreground-link-table link-table) ;;(if (and draw? (viewports-of self)) (erase-view self)) (unless (eql (link-table-of self) link-table) (link-table-link-view link-table self)) (when (and draw? (linked-views-of self) (drawing-styles-from-links self) (viewports-of self)) (draw-view self :erase? t))))) (defun link-highlit-views (&rest views ) (let* ((table (or (loop for v in views thereis (and (typep v 'link-table) v)) (use-link-table))) ) (loop for v in views when (typep v 'view) do (link-highlit-view v :draw? t :link-table table)))) (defmethod link-highlit-view ((self view) &key (draw? t) (link-table (use-link-table)) ) (loop for v in (subviews-of self) do (link-highlit-view v :draw? draw? :link-table link-table ))) (defmethod link-highlit-view ((self linkable-mixin) &key (draw? t) (link-table (use-link-table))) (if (draw-style self :highlight?) (let ((my-table (link-table-of self))) (unless (and my-table (eql my-table link-table)) (if (and my-table (not (eql my-table link-table))) (unlink-view self)) (foreground-link-table link-table) ;;(if (and draw? (viewports-of self)) (erase-view self)) (unless (eql (link-table-of self) link-table) (link-table-link-view link-table self)) (when (and draw? (linked-views-of self) (drawing-styles-from-links self) (viewports-of self)) (draw-view self :erase? t)))))) (defmethod drawing-styles-from-links ((self single-draw-style-mixin)) (let ((test (viewed-elt-test self)) (old-style (drawing-style-of self)) (links (linked-views-of self) ) (velt (car (list-viewed-elements self) )) (draw-styles-from-links ) (changed? nil)) (flet ((get-element-draw-style (i v) (or (nth i draw-styles-from-links) (let ((new (element-draw-style v velt test))) (setf draw-styles-from-links (nconc draw-styles-from-links (list new))) new)))) (loop for pair in old-style for key = (car pair) for new-val = (or (loop with val for v in links for i upfrom 0 for vstyle = (get-element-draw-style i v) thereis (and vstyle (setq val (or (draw-style vstyle key :default :none) :null)) (not (eq val :none)) val)) :none) when (eq new-val :null) do (setq new-val nil) unless (or (eq new-val :none) (eql new-val (cdr pair)) (and (eql key :font) (null (cdr pair)))) do (setf (cdr pair) (new-style-value key new-val pair)) (setf changed? t))) changed?)) (defmethod drawing-styles-from-links ((self multiple-draw-style-mixin)) (let ((test (viewed-elt-test self)) (links (linked-views-of self) ) (draw-styles-from-links nil) (changed? nil)) (flet ((get-element-draw-style (i v velt) (or (nth i draw-styles-from-links) (let ((new (element-draw-style v velt test))) (setf draw-styles-from-links (nconc draw-styles-from-links (list new))) new)))) (loop for vo in (list-viewed-elements self) for old-styles in (drawing-styles-of self) do (loop for pair in old-styles for key = (car pair) for new-val = (or (loop with val for v in links for i upfrom 0 for vstyle = (get-element-draw-style i v vo ) thereis (and vstyle (setq val (or (draw-style vstyle key :default :none) :null)) (not (eq val :none)) val)) :none) when (eq new-val :null) do (setq new-val nil) unless (or (eq new-val :none) (eql new-val (cdr pair))) do (setf changed? t) (setf (cdr pair) (new-style-value key new-val pair))) (setf draw-styles-from-links nil) ) changed?))) ;;---------------------------------------------------------------------------------------- (defun unlink-views (&rest views) (loop for v in views do (unlink-view v))) (defmethod unlink-view ((self view)) (loop for v in (subviews-of self) do (unlink-view v ))) (defmethod unlink-view ((self linkable-mixin)) (break-all-links self) (if (link-table-of self) (link-table-remove-view (link-table-of self) self))) (defmethod fast-link2-views((view1 view) (view2 view) &key (draw? t) link-table) (declare (ignore draw? link-table))) (defmethod fast-link2-views((s1 linkable-mixin) (s2 linkable-mixin) &key (draw? t) (link-table (use-link-table))) (if (and (link-table-of s1) (not (eql (link-table-of s1) link-table))) (background-link-table (link-table-of s1))) (if (and (link-table-of s2) (not (eql (link-table-of s2) link-table))) (background-link-table (link-table-of s2))) (foreground-link-table link-table) (cond ((and (link-table-of s1) (link-table-of s2)) nil) ((link-table-of s1) (loop for v in (linked-views-of s1) do (make-the-link v s2)) (make-the-link s1 s2) (link-table-add-view link-table s2) ) ((link-table-of s2) (loop for v in (linked-views-of s2) do (make-the-link v s1)) (make-the-link s1 s2) (link-table-add-view link-table s1) ) (t (make-the-link s1 s2) (link-table-add-view link-table s1) (link-table-add-view link-table s2) )) (if (and draw? (drawing-styles-from-links s1) (viewports-of s1)) (draw-view s1 :erase? t)) (if (and draw? (drawing-styles-from-links s2) (viewports-of s2)) (draw-view s2 :erase? t)) ) ;; Added do-nothing primary FEB 02, 1998 (defmethod set-highlight-style-on ((self linkable-mixin) &key (draw-links? t) elements on) (declare (ignore self draw-links? elements on)) (call-next-method)) (defmethod set-highlight-style-on :after ((self linkable-mixin) &key (draw-links? t) elements on) (if (and (linked-views-of self) draw-links?) (let ((linked-views (linked-views-of self)) ) (if (typep self 'multiple-draw-style-mixin) (loop for e in elements for d in (drawing-styles-of self) for hi = (draw-style d :highlight?) when (and e hi) do (loop for v in linked-views do (set-highlight-style v hi :draw-links? nil :element e :draw? t))) (when on (loop for v in linked-views do (set-highlight-style-on v :on t :draw-links? nil :elements elements :draw? t)))))))
15,452
Common Lisp
.l
325
34.744615
99
0.516299
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fd25c68465df1d4d7c9f9bbe98d6b0c7e448b0a01c34f1e93833e25cc65eabea
33,179
[ -1 ]
33,180
bordered-view-mixin.lsp
rwoldford_Quail/source/views/views-mixins/bordered-view-mixin.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; bordered-view-mixin.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( bordered-view-mixin default-margin-text interior-view-of interior-views-of left-view-of left-label-of left-views-of left-labels-of right-view-of right-label-of right-views-of right-labels-of bottom-view-of bottom-label-of bottom-views-of bottom-labels-of top-view-of top-label-of top-views-of top-labels-of *default-border-view-sizes* *default-border-label-sizes* *default-xy-ratio*))) (defvar *default-border-view-sizes* '(:left 0.1 :right 0.1 :bottom 0.07 :top 0.07)) (defvar *default-border-label-sizes* '(:left 0.07 :right 0.07 :bottom 0.07 :top 0.07)) (defvar *default-xy-ratio* nil) (defclass bordered-view-mixin (position-key-mixin) ((right-menu :allocation :class :initform nil) (position-keys :allocation :class :initform '(:left-view-size :right-view-size :bottom-view-size :top-view-size :bottom-label-size :top-label-size :left-label-size :right-label-size :xy-ratio) ) (interior-view :initarg :interior-view :initarg :interior-views :accessor interior-views-of :initform nil) (left-view :initarg :left-view :initarg :left-views :accessor left-views-of :initform nil) (left-label :initarg :left-label :initarg :left-labels :accessor left-labels-of :initform nil) (right-view :initarg :right-view :initarg :right-views :accessor right-views-of :initform nil) (right-label :initarg :right-label :initarg :right-labels :accessor right-labels-of :initform nil) (bottom-view :initarg :bottom-view :initarg :bottom-views :accessor bottom-views-of :initform nil) (bottom-label :initarg :bottom-label :initarg :bottom-labels :accessor bottom-labels-of :initform nil) (top-view :initarg :top-view :initarg :top-views :accessor top-views-of :initform nil) (top-label :initarg :top-label :initarg :top-labels :accessor top-labels-of :initform nil)) (:default-initargs :no-labels? nil :no-margin-views? nil :label-font nil :left-view-size (getf *default-border-view-sizes* :left) :right-view-size (getf *default-border-view-sizes* :right) :bottom-view-size (getf *default-border-view-sizes* :bottom) :top-view-size (getf *default-border-view-sizes* :top) :bottom-label-size (getf *default-border-label-sizes* :bottom) :top-label-size (getf *default-border-label-sizes* :top) :left-label-size (getf *default-border-label-sizes* :left) :right-label-size (getf *default-border-label-sizes* :right) :xy-ratio *default-xy-ratio*) (:documentation "Provides slots for interior-view,~ left, right bottom and top margin views~ and left, right bottom and top label views")) (defgeneric construct-margin-labels (bordered-view-mixin &key &allow-other-keys)) (defgeneric construct-margin-views (bordered-view-mixin &key &allow-other-keys)) (defgeneric construct-interior-view (bordered-view-mixin &key &allow-other-keys)) (defgeneric compute-interior-region (bordered-view-mixin &key &allow-other-keys)) (defgeneric init-position-margin-labels (bordered-view-mixin outer-space inner-space &key &allow-other-keys)) (defgeneric init-position-margin-views (bordered-view-mixin outer-space inner-space &key &allow-other-keys)) (defgeneric init-position-interior-view (bordered-view-mixin space &key &allow-other-keys)) (defgeneric init-position-interior-views (bordered-view-mixin space &key &allow-other-keys)) (defgeneric default-margin-text (bordered-view-mixin axis)) (defmethod construct-sub-views ((self bordered-view-mixin) &rest keyword-pairs &key all-subviews? no-labels? no-margin-views?) (if all-subviews? (with-accessors ((ll left-labels-of) (rl right-labels-of) (tl top-labels-of) (bl bottom-labels-of) (lv left-views-of) (rv right-views-of) (tv top-views-of) (bv bottom-views-of)) self (multiple-value-setq (tl bl rl ll lv rv bv tv) (values-list (loop for v in (list tl bl rl ll lv rv bv tv) collect (or v t)))))) (apply #'construct-interior-view self keyword-pairs ) (if no-margin-views? (progn (setf (left-views-of self) nil) (setf (right-views-of self) nil) (setf (bottom-views-of self) nil) (setf (top-views-of self) nil)) (apply #'construct-margin-views self keyword-pairs )) (if no-labels? (progn (setf (left-labels-of self) nil) (setf (right-labels-of self) nil) (setf (bottom-labels-of self) nil) (setf (top-labels-of self) nil)) (apply #'construct-margin-labels self keyword-pairs)) ) (defmethod init-label-text ((self bordered-view-mixin) (margin T) label) (if (typep label 'label) (let* ((iv (interior-view-of self)) (lab (text-of label))) (if (and (not (equal lab "")) (typep iv 'd-view) ) (if (equal lab (coord-string-x iv)) (text-link iv label :x) (if (equal lab (coord-string-y iv)) (text-link iv label :y))))))) (defmethod construct-margin-views ((self bordered-view-mixin) &rest keyword-pairs ) (declare (ignore keyword-pairs)) ) (defmethod construct-interior-view ((self bordered-view-mixin) &rest keyword-pairs ) (declare (ignore keyword-pairs))) (defmethod construct-margin-labels ((self bordered-view-mixin) &rest keyword-pairs ) (declare (ignore keyword-pairs))) (defmethod init-position-margin-views ((self bordered-view-mixin) outer-space inner-space &rest keyword-pairs ) (declare (ignore keyword-pairs outer-space inner-space)) ) (defmethod init-position-margin-labels ((self bordered-view-mixin) outer-space inner-space &rest keyword-pairs ) (declare (ignore keyword-pairs outer-space inner-space))) (defmethod init-position-interior-views ((self bordered-view-mixin) space &rest keyword-pairs ) (declare (ignore keyword-pairs space))) (defmethod init-position-interior-view ((self bordered-view-mixin) space &rest keyword-pairs ) (apply #'init-position-interior-views self space keyword-pairs )) (defmethod init-position-subviews ((self bordered-view-mixin) &rest keyword-pairs) (let ((outer-space (subview-position-region self)) (inner-space (apply #'compute-interior-region self keyword-pairs))) (apply #'init-position-interior-views self inner-space keyword-pairs) (apply #'init-position-margin-labels self outer-space inner-space keyword-pairs) (apply #'init-position-margin-views self outer-space inner-space keyword-pairs) (setf (subview-position-region-of self) inner-space) )) (defmethod interior-view-of ((self bordered-view-mixin)) (let ((v (slot-value self 'interior-view))) (if (listp v) (car v) v))) (defmethod left-view-of ((self bordered-view-mixin)) (let ((v (slot-value self 'left-view))) (if (listp v) (car v) v))) (defmethod right-view-of ((self bordered-view-mixin)) (let ((v (slot-value self 'right-view))) (if (listp v) (car v) v))) (defmethod bottom-view-of ((self bordered-view-mixin)) (let ((v (slot-value self 'bottom-view))) (if (listp v) (car v) v))) (defmethod top-view-of ((self bordered-view-mixin)) (let ((v (slot-value self 'top-view))) (if (listp v) (car v) v))) (defmethod left-label-of ((self bordered-view-mixin)) (let ((v (slot-value self 'left-label))) (if (listp v) (car v) v))) (defmethod right-label-of ((self bordered-view-mixin)) (let ((v (slot-value self 'right-label))) (if (listp v) (car v) v))) (defmethod bottom-label-of ((self bordered-view-mixin)) (let ((v (slot-value self 'bottom-label))) (car v))) (defmethod top-label-of ((self bordered-view-mixin)) (let ((v (slot-value self 'top-label))) (if (listp v) (car v) v))) (defmethod (setf interior-view-of) (view (self bordered-view-mixin)) (setf (slot-value self 'interior-view) (list view))) (defmethod (setf left-view-of) (view (self bordered-view-mixin)) (setf (slot-value self 'left-view) (list view))) (defmethod (setf right-view-of) (view (self bordered-view-mixin)) (setf (slot-value self 'right-view) (list view))) (defmethod (setf bottom-view-of) (view (self bordered-view-mixin)) (setf (slot-value self 'bottom-view) (list view))) (defmethod (setf top-view-of) (view (self bordered-view-mixin)) (setf (slot-value self 'top-view) (list view))) (defmethod (setf left-label-of) (view (self bordered-view-mixin)) (setf (slot-value self 'left-label) (list view))) (defmethod (setf right-label-of) (view (self bordered-view-mixin)) (setf (slot-value self 'right-label) (list view))) (defmethod (setf bottom-label-of) (view (self bordered-view-mixin)) (setf (slot-value self 'bottom-label) (list view))) (defmethod (setf top-label-of) (view (self bordered-view-mixin)) (setf (slot-value self 'top-label) (list view)))
10,970
Common Lisp
.l
204
42.720588
94
0.599429
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
049aea8b6925fc5459bff63acf7bea9d0f46691b7ce029289cda3dc03c795aa2
33,180
[ -1 ]
33,181
link.lsp
rwoldford_Quail/source/views/views-mixins/link.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; link.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(linkable-mixin link-views link-highlit-view unlink-views link-view unlink-view get-link-table fast-link2-views))) (defclass linkable-mixin () ((linked-views :initform nil :initarg :linked-views :accessor linked-views-of) (private-styles :initform nil :initarg :private-styles :accessor private-styles-of) (link-table :initform nil :accessor link-table-of) (linkable? :initform t :initarg :linkable? :accessor linkable-view-p))) (defgeneric get-link-table(view) (:documentation "Returns a link table from the hierarchy of view")) (defgeneric fast-link2-views(view1 view2 &key draw? link-table) (:documentation "Links the two views. Does not compare the viewed elements ")) (defgeneric linkable-view-p(view) (:documentation "Is a view linkable?")) ;;;---------------------------------------------------------------------------------- (defmethod link-table-of ((self view)) nil) (defmethod linked-views-of ((self view)) nil) (defmethod linkable-view-p ((self view)) nil) (defmethod get-link-table((self view)) (some #'get-link-table (subviews-of self))) (defmethod get-link-table((self linkable-mixin)) (link-table-of self)) #| (defmethod viewed-elt-test ((self linkable-mixin)) (let ((tab (link-table-of self))) (if tab (link-table-test-of tab) (call-next-method)))) |# ;; on 2/22/95 changed code so that iteration over (list-viewed-elements self) is done ;; on the linked view if necessary. This version will be more efficient because ;; simple-style-mixins will not need to do this iteration. (defmethod set-linkable-styles ((self linkable-mixin) styles) (when styles (setf (private-styles-of self) (set-difference (list-style-keys (drawing-style-of self)) styles)))) (defmethod set-drawing-style :after ((self linkable-mixin) &key test (draw-links? t) element styles (draw? t) (erase? draw?) highlit?) (if (and (linked-views-of self) draw-links?) (let ((linked-views (linked-views-of self)) (my-private-styles (private-styles-of self))) (if my-private-styles (setq styles (loop for key in styles by #'cddr for val in (cdr styles) by #'cddr unless (member key my-private-styles) collect key and collect val))) (if (or element highlit?) (let* ((ltest (or test (viewed-elt-test self))) (elements (cond (element (loop for ve in (list-viewed-elements self) when (funcall ltest ve element) collect ve)) ((and (eq highlit? t) (typep self 'multiple-draw-style-mixin)) (loop for ve in (list-viewed-elements self) for d in (drawing-styles-of self) when (draw-style d :highlight?) collect ve)) ((eq highlit? t) (if (draw-style self :highlight?) (list-viewed-elements self))) ((typep self 'multiple-draw-style-mixin) (or (loop for ve in (list-viewed-elements self) for d in (drawing-styles-of self) when (draw-style d :highlight?) collect ve) (list-viewed-elements self))) (t (list-viewed-elements self))))) (when elements (if (eql elements (list-viewed-elements self)) (setq elements nil)) (loop with test = (link-table-test-of (link-table-of self)) for v in linked-views for v-private-styles = (private-styles-of v) for v-new-styles = (if v-private-styles (loop for key in styles by #'cddr for val in (cdr styles) by #'cddr unless (member key v-private-styles) collect key and collect val) styles) do (set-drawing-style v :draw-links? nil :elements elements :from self :test test :styles v-new-styles :draw? draw? :erase? erase?)))) (loop with test = (link-table-test-of (link-table-of self)) for v in linked-views for v-private-styles = (private-styles-of v) for v-new-styles = (if v-private-styles (loop for key in styles by #'cddr for val in (cdr styles) by #'cddr unless (member key v-private-styles) collect key and collect val) styles) do (set-drawing-style v :draw-links? nil :from self :test test :draw? draw? :erase? erase? :styles v-new-styles)) )))) ;;; Added do-nothing primary FEB 02,1998 (defmethod set-highlight-style ((self linkable-mixin) hi-val &key (draw-links? t) element (draw? t) (erase? draw?)) (declare (ignorable self hi-val draw-links? element erase?)) ;(declare (ignore self hi-val draw-links? element erase?)) ;29JUL2023 (call-next-method)) (defmethod set-highlight-style :after ((self linkable-mixin) hi-val &key (draw-links? t) test element (draw? t) (erase? draw?)) (if (and (linked-views-of self) draw-links?) (let ((linked-views (linked-views-of self)) (my-private-styles (private-styles-of self))) (if (not (member :highlight? my-private-styles)) (if element (let* ((ltest (or test (viewed-elt-test self))) (elements (loop for ve in (list-viewed-elements self) when (funcall ltest ve element) collect ve))) (loop with test = (link-table-test-of (link-table-of self)) for v in linked-views for v-private-styles = (private-styles-of v) unless (member :highlight? v-private-styles) do (set-highlight-style v hi-val :draw-links? nil :elements elements :from self :test test :draw? draw? :erase? erase?))) (loop with test = (link-table-test-of (link-table-of self)) for v in linked-views for v-private-styles = (private-styles-of v) unless (member :highlight? v-private-styles) do (set-highlight-style v hi-val :draw-links? nil :from self :test test :draw? draw? :erase? erase?)) ))))) (defmethod highlight-operation ((self linkable-mixin)) :default ) ;;------------------------------------------------------------------------------------ (defun link-views (&rest views ) "Link the views. ~ More specifically, the linkable descendants of views are added ~ to a link table.~ If an argument is a link table, than that link table is used,~ otherwise the user is prompted for a link table, if more than ~ one link table is available." (let* ((table (or (loop for v in views thereis (and (typep v 'link-table) v)) (use-link-table))) ) (loop for v in views when (typep v 'view) do (link-view v :draw? t :link-table table)))) (defgeneric link-view (view &key draw? type link-table styles) (:documentation "Link the view. ~ More specifically, the linkable descendants of view are added ~ to a link table.~ (:key ~ (:arg draw? t Specifies if the view should be redrawn, with drawing styles from its linked views. ) ~ (:arg link-table :default Should be a link table. If is not provided,~ the user is prompted for a link table, if more than ~ one link table is available.)~ (:arg type NIL If provided, only linkable views of this type are linked..) (:arg styles NIL If provided, only these drawing styles are linked..) )" )) (defgeneric unlink-view (view &key) (:documentation "Unlinks the view. ~ More specifically, the linkable descendants of view are removed ~ from a link table.")) (defmethod link-view ((self view) &key (draw? t) type styles (link-table (use-link-table)) (to-views :all) (fast? t)) (if (and fast? (eq :all to-views)) (let* ((one-per-case (descendant-views-of-type self 'one-per-case-mixin)) (d (car one-per-case))) (when (and one-per-case (not (typep link-table 'asymmetric-link-table))) (link-view d :draw? draw? :type type :link-table link-table :fast? nil :styles styles) (if type (loop for di in (cdr one-per-case) when (eq (viewed-object-of di) (viewed-object-of d)) do (loop for a in (subviews-of d) for b in (subviews-of di) for aelts = (list-viewed-elements a) when (and (linkable-view-p a) (linkable-view-p b) (typep a type) (typep b type) aelts (eq aelts (list-viewed-elements b))) do (fast-link2-views a b :draw? draw? :link-table link-table :styles styles))) (loop for di in (cdr one-per-case) when (eq (viewed-object-of di) (viewed-object-of d)) do (loop for a in (subviews-of d) for b in (subviews-of di) for aelts = (list-viewed-elements a) when (and aelts (eq aelts (list-viewed-elements b))) do (fast-link2-views a b :draw? draw? :link-table link-table :styles styles))))))) (loop with to = (if (eq to-views :old) (link-table-views-of link-table) to-views) for v in (subviews-of self) do (link-view v :draw? draw? :type type :link-table link-table :fast? nil :to-views to :styles styles))) (defmethod link-view ((self linkable-mixin) &key styles (draw? t) type (to-views :all) (link-table (use-link-table))) (when (and (linkable-view-p self) (or (null type) (typep self type))) (if styles (set-linkable-styles self styles)) (let ((my-table (link-table-of self))) (unless (and my-table (eql my-table link-table)) (if (and my-table (not (eql my-table link-table))) (unlink-view self)) (foreground-link-table link-table) ;;(if (and draw? (viewports-of self)) (erase-view self)) (unless (eql (link-table-of self) link-table) (link-table-link-view link-table self to-views)) (when (and draw? (linked-views-of self) (drawing-styles-from-links self) (viewports-of self)) (draw-view self :erase? t))))) (loop with to = (if (eq to-views :old) (link-table-views-of link-table) to-views) for v in (subviews-of self) do (link-view v :draw? draw? :type type :link-table link-table :fast? nil :to-views to :styles styles))) (defun link-highlit-views (&rest views ) (let* ((table (or (loop for v in views thereis (and (typep v 'link-table) v)) (use-link-table))) ) (loop for v in views when (typep v 'view) do (link-highlit-view v :draw? t :link-table table)))) (defmethod link-highlit-view ((self view) &key (draw? t) (link-table (use-link-table)) ) (loop for v in (subviews-of self) do (link-highlit-view v :draw? draw? :link-table link-table ))) (defun unlink-highlit-views (&rest views ) (loop for v in views when (typep v 'view) do (unlink-highlit-view v))) (defmethod unlink-highlit-view ((self view)) (loop for v in (subviews-of self) do (unlink-highlit-view v ))) (defmethod link-highlit-view ((self linkable-mixin) &key (draw? t) (link-table (use-link-table))) (if (and (linkable-view-p self) (draw-style self :highlight?)) (let ((my-table (link-table-of self))) (unless (and my-table (eql my-table link-table)) (if (and my-table (not (eql my-table link-table))) (unlink-view self)) (foreground-link-table link-table) ;;(if (and draw? (viewports-of self)) (erase-view self)) (unless (eql (link-table-of self) link-table) (link-table-link-view link-table self)) (when (and draw? (linked-views-of self) (drawing-styles-from-links self) (viewports-of self)) (draw-view self :erase? t))))) (loop for v in (subviews-of self) do (link-highlit-view v :draw? draw? :link-table link-table ))) (defmethod drawing-styles-from-links ((self single-draw-style-mixin)) (let ((test (link-table-test-of (link-table-of self))) (old-style (drawing-style-of self)) (links (linked-views-of self) ) (velt (car (list-viewed-elements self) )) (private-styles (private-styles-of self)) (draw-styles-from-links ) (changed? nil)) (flet ((get-element-draw-style (i v) (or (nth i draw-styles-from-links) (let ((new (element-draw-style v velt test))) (setf draw-styles-from-links (nconc draw-styles-from-links (list new))) new)))) (loop with new-val for pair in old-style for key = (car pair) unless (member key private-styles) do (setq new-val (or (loop with val for v in links for styles-v = (private-styles-of v) for i upfrom 0 for vstyle = (get-element-draw-style i v) thereis (and (not (member key styles-v)) vstyle (setq val (or (draw-style vstyle key :default :none) :null)) (not (eq val :none)) val)) :none)) (when (eq new-val :null) (setq new-val nil)) (unless (or (eq new-val :none) (eql new-val (cdr pair)) (and (eql key :font) (null (cdr pair)))) (setf (cdr pair) (new-style-value key new-val pair)) (setf changed? t)))) changed?)) (defmethod drawing-styles-from-links ((self multiple-draw-style-mixin)) (let ((test (link-table-test-of (link-table-of self))) (links (linked-views-of self) ) (private-styles (private-styles-of self)) (draw-styles-from-links nil) (changed? nil)) (flet ((get-element-draw-style (i v velt) (or (nth i draw-styles-from-links) (let ((new (element-draw-style v velt test))) (setf draw-styles-from-links (nconc draw-styles-from-links (list new))) new)))) (loop for vo in (list-viewed-elements self) for old-styles in (drawing-styles-of self) do (loop with new-val for pair in old-styles for key = (car pair) unless (member key private-styles) do (setq new-val (or (loop with val for v in links for styles-v = (private-styles-of v) for i upfrom 0 for vstyle = (get-element-draw-style i v vo ) thereis (and (not (member key styles-v)) vstyle (setq val (or (draw-style vstyle key :default :none) :null)) (not (eq val :none)) val)) :none)) (when (eq new-val :null) (setq new-val nil) ) (unless (or (eq new-val :none) (eql new-val (cdr pair))) (setf changed? t) (setf (cdr pair) (new-style-value key new-val pair)))) (setf draw-styles-from-links nil) ) changed?))) ;;---------------------------------------------------------------------------------------- (defun unlink-views (&rest views) (loop for v in views do (unlink-view v))) (defmethod unlink-view ((self view) &key type) (loop for v in (subviews-of self) do (unlink-view v :type type))) (defmethod unlink-view ((self linkable-mixin) &key type) (if (and (or (null type) (typep self type)) (link-table-of self)) (link-table-remove-view (link-table-of self) self)) (loop for v in (subviews-of self) do (unlink-view v :type type))) (defmethod unlink-highlit-view ((self linkable-mixin) ) (if (and (link-table-of self) (draw-style self :highlight?)) (link-table-remove-view (link-table-of self) self)) (loop for v in (subviews-of self) do (unlink-highlit-view v ))) (defmethod fast-link2-views((view1 view) (view2 view) &key type (draw? t) (link-table (use-link-table)) styles) (let ((list1 (descendant-views-of-type view1 `(and linkable-mixin ,type))) (list2 (descendant-views-of-type view2 `(and linkable-mixin ,type)))) (when (= (length list1) (length list2)) (loop for v1 in list1 for v2 in list2 do (fast-link2-views v1 v2 :link-table link-table :styles styles :draw? draw?))))) (defmethod fast-link2-views((s1 linkable-mixin) (s2 linkable-mixin) &key styles (draw? t) (link-table (use-link-table))) (set-linkable-styles s1 styles) (set-linkable-styles s2 styles) (if (and (link-table-of s1) (not (eql (link-table-of s1) link-table))) (background-link-table (link-table-of s1))) (if (and (link-table-of s2) (not (eql (link-table-of s2) link-table))) (background-link-table (link-table-of s2))) (foreground-link-table link-table) (let ((view-test (link-table-test-of link-table))) (cond ((and (link-table-of s1) (link-table-of s2)) nil) ((linked-views-of s1) (loop for v in (linked-views-of s1) when (or (null view-test) (funcall view-test v s2)) do (make-double-links v s2)) (when (or (null view-test) (funcall view-test s1 s2)) (make-double-links s1 s2)) (link-table-add-view link-table s2) ) ((linked-views-of s2) (loop for v in (linked-views-of s2) when (or (null view-test) (funcall view-test v s1)) do (make-double-links v s1)) (when (or (null view-test) (funcall view-test s1 s2)) (make-double-links s1 s2)) (link-table-add-view link-table s1) ) (t (when (or (null view-test) (funcall view-test s1 s2)) (make-double-links s1 s2)) (make-double-links s1 s2) (link-table-add-view link-table s1) (link-table-add-view link-table s2) ))) (if (and draw? (drawing-styles-from-links s1) (viewports-of s1)) (draw-view s1 :erase? t)) (if (and draw? (drawing-styles-from-links s2) (viewports-of s2)) (draw-view s2 :erase? t)) )
21,573
Common Lisp
.l
411
37.364964
135
0.518779
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
02c684028b2a811944e50118920b65b02a32a2d2f710a559445538f3605061a7
33,181
[ -1 ]
33,182
link-table.lsp
rwoldford_Quail/source/views/views-mixins/link-table.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; link-table.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(link-table asymmetric-link-table link-table-add-view set-link-table-test use-link-table link-table-remove-view link-table-clear show-links make-link-table *default-link-table* default-link-table foreground-link-table background-link-table choose-link-table delete-link-table delete-link-tables))) ;;;---------------------------------------------------------------------------------- (defvar *default-link-table* nil) (setq *default-link-table* nil) (defgeneric link-table-add-view(link-table view) (:documentation "Adds view to the link-table.")) (defgeneric link-table-remove-view(link-table view) (:documentation "Removes view from the link-table.")) (defvar *foreground-link-tables* nil) (defvar *background-link-tables* nil) (defclass link-table() ((test :initarg :test :accessor link-table-test-of) (view-test :initarg :view-test :accessor link-table-view-test-of) (saved-links :initform nil :accessor saved-links-of) (name :initform nil :initarg :name :accessor link-table-name-of) (views :initform nil :accessor link-table-views-of))) (defclass asymmetric-link-table(link-table) ()) (defmethod link-table-test-of :before ((self link-table)) (if (null (slot-value self 'test)) (setf (slot-value self 'test) #'(lambda(a b) (declare (ignore a b)) t)))) (defmethod link-table-name-of ((self link-table)) (or (slot-value self 'name) (string (qk::function-name (link-table-test-of self))))) (defun set-link-table-test (new-test &key (link-table (default-link-table)) (rebuild-links? t) (draw? rebuild-links?)) "Sets the test of link-table to new-test." (setf (link-table-test-of link-table) new-test) (when rebuild-links? (let ((views (link-table-views-of link-table))) (link-table-clear link-table) (loop for v in views do (link-view v :link-table link-table :draw? draw?))) )) (defun set-link-table-view-test (new-test &key (link-table (default-link-table))) "Sets the test of link-table to new-test." (setf (link-table-view-test-of link-table) new-test) (loop for v in (link-table-views-of link-table) do (setf (linked-views-of v) (loop for s in (linked-views-of v) when (funcall new-test v s) collect s)))) (defun make-double-links (v1 v2) (push v1 (linked-views-of v2)) (push v2 (linked-views-of v1))) (defun make-the-link (v1 v2) (push v2 (linked-views-of v1))) ;;---------------------------------------------------------------------------------------- (defun show-links( &key (test #'identity) (sleep 1) (link-table (default-link-table))) "Selects links, one at a time" (loop for v in (link-table-views-of link-table) when (funcall test v) do (select-one v) (sleep sleep))) (defmethod link-table-add-view((self link-table) view) (setf (link-table-of view) self) (push view (link-table-views-of self)) view) (defmethod link-table-remove-view((self link-table) view) (loop for link in (linked-views-of view) do (setf (linked-views-of link) (delete view (linked-views-of link)))) (setf (linked-views-of view) nil) (setf (link-table-of view) nil) (setf (link-table-views-of self) (remove view (link-table-views-of self)))) (defmethod link-table-remove-view((self asymmetric-link-table) view) (loop for link in (link-table-views-of self) do (setf (linked-views-of link) (delete view (linked-views-of link)))) (setf (linked-views-of view) nil) (setf (link-table-of view) nil) (setf (link-table-views-of self) (remove view (link-table-views-of self)))) (defun link-table-clear (&optional (link-table (default-link-table))) "Clears the link-table. ~ If a link-table is not specified, the ~ default link-table is cleared." (loop for v in (link-table-views-of link-table) do (setf (linked-views-of v) nil) (setf (link-table-of v) nil)) (setf (link-table-views-of link-table) nil)) (defun delete-link-table (&optional (link-table (default-link-table))) "Deletes the link-table. ~ If a link-table is not specified, the ~ default link-table is deleted." (declare (special *foreground-link-tables* *background-link-tables*)) (loop for v in (link-table-views-of link-table) do (setf (linked-views-of v) nil) (setf (link-table-of v) nil)) (setf (link-table-views-of link-table) nil) (setq *foreground-link-tables* (remove link-table *foreground-link-tables*)) (setq *background-link-tables* (remove link-table *background-link-tables*))) (defun delete-link-tables () "Deletes all link-tables. " (declare (special *default-link-table* *foreground-link-tables* *background-link-tables* )) (let ((all-tables (append *foreground-link-tables* *background-link-tables*))) (deselect-all) (setq *foreground-link-tables* nil) (setq *background-link-tables* nil) (mapcar #'delete-link-table all-tables) (setq *default-link-table* nil))) (defun make-link-table (&key view-test (test *default-data-eq*) (symmetric? t) name) (declare (special *foreground-link-tables*)) (let ((lt (if symmetric? (make-instance 'link-table :test test :name name :view-test view-test) (make-instance 'asymmetric-link-table :test test :name name :view-test view-test)))) (push lt *foreground-link-tables*) lt)) (defmethod link-table-link-view((self link-table) view &optional linked-views) (let* ((list-vo (list-viewed-elements view)) (nlist-vo (length list-vo)) (view-test (link-table-view-test-of self)) (test (link-table-test-of self)) other-view) (if (eq linked-views :all) (setq linked-views (link-table-views-of self))) (flet ((same-dataset?(v bview) (declare (ignore v)) (let ((list-vob (list-viewed-elements bview))) (or (eql list-vob list-vo) (and (= nlist-vo (length list-vob)) (every #'eq list-vo list-vob)))))) (if (and (null view-test) list-vo (setq other-view (find view linked-views :test #'same-dataset?))) (loop for v in (linked-views-of other-view) do (make-double-links v view) finally (make-double-links view other-view)) (flet ((common-dataset?(bview) (loop for b in (list-viewed-elements bview) thereis (loop for a in list-vo thereis (funcall test a b) )))) (if view-test (loop for v in linked-views when (and (funcall view-test view v) (common-dataset? v)) do (make-double-links view v)) (loop for v in linked-views when (common-dataset? v) do (make-double-links view v))))))) (link-table-add-view self view)) (defmethod link-table-link-view((self asymmetric-link-table) view &optional linked-views) (let* ((view-list-vo (list-viewed-elements view)) (test (link-table-test-of self)) (view-test (link-table-view-test-of self)) ) (if (eq linked-views :all) (setq linked-views (link-table-views-of self))) (flet ((common-dataset?(alist blist) (loop for b in blist thereis (loop for a in alist thereis (funcall test a b) )))) (if view-test (loop for v in linked-views for v-list-vo = (list-viewed-elements v) do (if (and (funcall view-test v view) (common-dataset? v-list-vo view-list-vo) ) (make-the-link v view)) (if (and (funcall view-test view v) (common-dataset? view-list-vo v-list-vo)) (make-the-link view v )) ) (loop for v in linked-views for v-list-vo = (list-viewed-elements v) do (if (common-dataset? v-list-vo view-list-vo) (make-the-link v view)) (if (common-dataset? view-list-vo v-list-vo) (make-the-link view v )) )))) (link-table-add-view self view)) (defun background-link-table(&optional (link-table (default-link-table))) (declare (special *background-link-tables* *foreground-link-tables*)) (unless (or (null link-table) (member link-table *background-link-tables*)) (setf (saved-links-of link-table) (loop for v in (link-table-views-of link-table) collect (linked-views-of v))) (loop for v in (link-table-views-of link-table) do (setf (linked-views-of v) nil) (setf (link-table-of v) nil)) (push link-table *background-link-tables*) (setq *foreground-link-tables* (remove link-table *foreground-link-tables*))) link-table) (defun foreground-link-table(&optional (link-table (default-link-table))) (declare (special *background-link-tables* *foreground-link-tables*)) (unless (or (null link-table) (member link-table *foreground-link-tables*)) (loop for v in (link-table-views-of link-table) for sv in (saved-links-of link-table) do (setf (linked-views-of v) sv) (setf (link-table-of v) link-table)) (setf (saved-links-of link-table) nil) (push link-table *foreground-link-tables*) (setf *background-link-tables* (remove link-table *background-link-tables*))) link-table) (defun default-link-table(&optional lt) (declare (special *default-link-table*)) (setq *default-link-table* (cond ((typep lt 'link-table) lt) ((eql lt :choose) (choose-link-table)) ((and *default-link-table* (member *default-link-table* *foreground-link-tables*)) *default-link-table*) (t (choose-link-table)))) ) (defun use-link-table(&optional lt) (declare (special *default-link-table*)) (cond ((eql lt :choose) (choose-link-table)) ((and *default-link-table* (member *default-link-table* *foreground-link-tables*)) *default-link-table*) ((eq lt :default) (setq *default-link-table* (choose-link-table))) (t (choose-link-table))) ) (defun choose-link-table(&optional table-list) (declare (special *background-link-tables* *foreground-link-tables*)) (setq table-list (or table-list (append *foreground-link-tables* *background-link-tables*))) (cond ((and table-list (= 1 (length table-list))) (car table-list)) ((null table-list) (make-link-table :name "Default")) (t (first (wb:prompt-for-items table-list :item-function #'link-table-name-of))))) (defun choose-link-tables(table-list) (cond ((and table-list (= 1 (length table-list))) table-list) (table-list (wb:prompt-for-items table-list :item-function #'link-table-name-of)) (t nil)))
12,568
Common Lisp
.l
263
37.547529
154
0.575732
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
8ad982d2874407ef464068350311c5ca40d15c4b960b20b84484c9f19c3ec703
33,182
[ -1 ]
33,183
mixin.lsp
rwoldford_Quail/source/views/views-mixins/mixin.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; mixins.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( orientation-mixin justification-mixin viewport-coords-cache-mixin boxed-view-mixin boxed-subview-mixin bg-color-mixin square-view-mixin *bg-color* pass-draws-to-subviews set-orientation set-justification get-viewed-obj-styles styles-cache flip-mixin view-with-size set-box-p set-box-views-p box-color-mixin set-flip-x-p set-flip-y-p set-viewport-coords viewport-coords-of remove-viewport-coords list-legal-justifications viewed-elements-cache viewed-elements-of ))) (defclass viewport-coords-cache-mixin () ((viewport-coords-cache :initarg :viewport-coords-cache :initform nil :accessor viewport-coords-cache-of ) (viewport-compute-method :initarg :viewport-compute-method :initform nil :accessor viewport-compute-method-of) )) (defclass view-with-size () ((view-size :initform 10 :initarg :size :accessor view-size-of) (size-menu? :initform t :initarg :size-menu? :accessor size-menu-p)) ) (defclass fixed-size-rectangle () ((rectangle-width :initform nil :initarg :rectangle-width :accessor rectangle-width-of) (rectangle-height :initform nil :initarg :rectangle-height :accessor rectangle-height-of) (size-menu? :initform t :initarg :size-menu? :accessor size-menu-p)) ) (defclass pass-draws-to-subviews () ()) (defclass flip-mixin () ((flip-x :initarg :flip-x? :accessor flip-x-p :initform nil) (flip-y :initarg :flip-y? :accessor flip-y-p :initform nil))) (defclass orientation-mixin () ((orientation :initarg :orientation :initform :horizontal :accessor orientation-of :documentation ":horizontal or :vertical") (orientation-menu? :initarg :orientation-menu? :initform t :accessor orientation-menu-p) ) (:default-initargs :orientation :horizontal)) (defclass justification-mixin () ((justification :initarg :justification :initform :center :accessor justification-of :documentation "Determines justification of view in viewport. ~ Legal justifications are at least~ :left :right :top :bottom or :center") (justification-menu? :initarg :justification-menu? :initform t :accessor justification-menu-p)) (:default-initargs :justification :center :orientation :horizontal :justification-menu? t )) (defclass box-color-mixin () ((style-keys :initform '(:box-color) :allocation :class) (box-color-menu? :initarg :box-color-menu? :initform t :accessor box-color-menu-p)) (:default-initargs :box-color nil ) (:documentation "Used by boxed-view-mixin and boxed-subview-mixin ")) (defclass boxed-view-mixin (box-color-mixin) ((box :initarg :box? :initform t :accessor box-p) (box-margin :initarg :box-margin :initform 0 :accessor box-margin-of) (box-menu? :initarg :box-menu? :initform t :accessor box-menu-p)) (:documentation "Mix in this with box-p non-nil to get a view with a box around it")) (defclass boxed-subview-mixin (box-color-mixin) ((box-views? :initform t :initarg :box-views? :accessor box-views-p) (subview-box-margin :initarg :subview-box-margin :initform 0 :accessor subview-box-margin-of) (box-views-menu? :initarg :box-views-menu? :initform t :accessor box-views-menu-p)) (:documentation "Mix in this with box-p non-nil to get a view which~ draws boxes around its subviews.")) (defclass bg-color-mixin () ((style-keys :initform '(:bg-color) :allocation :class) (bg-color-menu? :initarg :bg-color-menu? :initform t :accessor bg-color-menu-p)) (:default-initargs :bg-color wb:*default-canvas-background-color* ) (:documentation "Mix this in last for a background color.~ Should also add bg-color to style-keys")) (defclass square-view-mixin () () (:documentation "Views with this mixin will appear in the ~ largest square centered in the viewport")) (defclass styles-cache () ((viewed-obj-styles :initform nil :accessor viewed-obj-styles-of :documentation "A cache for draw styles ordered by viewed-object, may be mixed into d-views"))) (defgeneric get-viewed-obj-styles (styles-cache &key &allow-other-keys) (:documentation "returns draw-styles in order of viewed-objects")) (defgeneric set-flip-x-p (flip-mixin val &key draw? ) (:documentation "Flips the x axis of view.")) (defgeneric set-flip-y-p (flip-mixin val &key draw? ) (:documentation "Flips the y axis of view.")) (defgeneric viewport-coords-of (viewport-coords-cache-mixin &key viewport) (:documentation "Returns the viewport coords")) (defgeneric set-viewport-coords (viewport-coords-cache-mixin &key viewport coords) (:documentation "SEts the coords for viewport")) ;;;---------------------------------------------------------------------------------- (defmethod axis-of-orientation ((self orientation-mixin)) (ecase (orientation-of self) (:horizontal :x) (:vertical :y))) (defmethod (setf axis-of-orientation) (axis (self orientation-mixin)) (setf (orientation-of self) (ecase axis (:x :horizontal ) (:y :vertical )))) (defmethod extent-of ((self orientation-mixin)) (multiple-value-bind (l r b tp) (bounds-of (bounding-region-of self)) (ecase (orientation-of self) (:horizontal (values l r)) (:vertical (values b tp))))) (defmethod region-of-extent ((self orientation-mixin) min max) (ecase (orientation-of self) (:horizontal (make-region min max 0 1)) (:vertical (make-region 0 1 min max )))) (defmethod (setf extent-of) (new-vals (self orientation-mixin)) (let ((br (bounding-region-of self)) ) (if (interval-p new-vals) (setq new-vals (list (min-of new-vals) (max-of new-vals)))) (ecase (orientation-of self) (:horizontal (setf (x-extent-of br) new-vals)) (:vertical (setf (y-extent-of br) new-vals) ) ))) (defmethod expand-extent ( (self orientation-mixin) new-vals) (let ((br (bounding-region-of self)) min max) (if (interval-p new-vals) (setf min (min-of new-vals) max (max-of new-vals)) ( setf min (first new-vals) max (second new-vals))) (ecase (orientation-of self) (:horizontal (setf (left-of br) (min (left-of br) min) ) (setf (right-of br) (max (right-of br) max))) (:vertical (setf (bottom-of br) (min (bottom-of br) min)) (setf (top-of br) (max (top-of br) max)) )))) (defmethod orientation-of :before ((self orientation-mixin)) (if (eq :prompt (slot-value self 'orientation)) (setf (slot-value self 'orientation) (car (wb:prompt-for-items (list :horizontal :vertical) :prompt-text "Choose orientation"))))) (defmethod set-orientation ((self orientation-mixin) orientation &key (draw? nil) ) (if (eq orientation :toggle) (setq orientation (if (eq (orientation-of self) :horizontal) :vertical :horizontal))) (setf (orientation-of self) orientation) (set-bounding-region self ) (init-position-subviews self) (if draw? (remap-to-viewports self))) (defmethod get-menu-items :around ((self orientation-mixin) (slot-name (eql 'middle-menu))) (let (( menu-list (call-next-method))) (if (orientation-menu-p self) (append menu-list `(( "Orientation" (set-orientation :toggle :draw? T) "Toggle the orientation." :sub-items (("Toggle" (set-orientation :toggle :draw? T)) ("Horizontal" (set-orientation :horizontal :draw? T)) ("Vertical" (set-orientation :vertical :draw? T)))) )) menu-list))) ;;;---------------------------------------------------------------------------------- (defmethod list-legal-justifications ((self justification-mixin)) (list :left :right :x-center :bottom :top :y-center)) (defmethod set-justification ((self justification-mixin) justification &key (draw? nil) ) (setf (justification-of self) justification) (set-bounding-region self ) (init-position-subviews self) (if draw? (remap-to-viewports self))) (defmethod justification-of :before ((self justification-mixin)) (if (eq :prompt (slot-value self 'justification)) (setf (slot-value self 'justification) (car (wb:prompt-for-items (list-legal-justifications self) :prompt-text "Choose justification"))))) (defmethod get-menu-items :around ((self justification-mixin) (slot-name (eql 'middle-menu))) (let (( menu-list (call-next-method))) (if (justification-menu-p self) (append menu-list `(( "Justification" (set-justification :prompt :draw? T) "Prompt for a change in the justification of the text."))) menu-list))) ;;;---------------------------------------------------------------------------------- (defgeneric set-box-p (boxed-view-mixin val &key draw?) (:documentation "Changes the parameter which controls whether or not~ a box is drawn around the views.")) (defmethod set-box-p ((self boxed-view-mixin) val &key (draw? t)) (if (eql val :toggle) (setq val (not (box-p self)))) (if draw? (erase-view self)) (setf (box-p self) val) (if draw? (draw-view self :erase? nil))) ;; (defmethod draw-view :after ((self boxed-view-mixin) &key viewport) (when (box-p self) (with-exposed-viewports self viewport vp (draw-viewport vp :color (draw-style self :box-color) :margin (box-margin-of self))))) (defmethod get-menu-items :around ((self boxed-view-mixin) (slot-name (eql 'middle-menu))) (if (box-menu-p self) (add-menu-items self '(("Boxes?" (set-box-p :toggle )) ) (call-next-method)) (call-next-method))) ;; added 11/95 (defmethod erase-view :after ((self boxed-view-mixin) &key viewport) (when (box-p self) (with-exposed-viewports self viewport vp (draw-viewport vp :color (draw-style self :box-color) :operation :boole-andc1 :margin (box-margin-of self))))) (defmethod update-menu-items :after ((self boxed-view-mixin) (slot-name (eql 'middle-menu))) (let* ((m (slot-value self slot-name))) (if (box-menu-p self) (wb:check-menu-item m "Boxes?" (box-p self))) (if (box-color-menu-p self) (if (box-p self) (wb:enable-menu-item m "BoxColor") (wb:disable-menu-item m "BoxColor"))))) ;;;---------------------------------------------------------------------------------- (defun box-color-menu-items () (declare (special *color-menu-list* *shade-menu-list*)) (loop for c in (if (wb:color-device-p) *color-menu-list* *shade-menu-list*) collect (list (car c) `(set-drawing-style :box-color ,(cadr c))))) (defmethod style-menu-items :around ((self box-color-mixin)) (let ((result (call-next-method))) ( if (box-color-menu-p self) (add-menu-items self `( ( "BoxColor" nil "" :sub-items ,(box-color-menu-items)) ) result) result))) ;;;---------------------------------------------------------------------------------- (defgeneric set-box-views-p (boxed-subview-mixin val &key draw?) (:documentation "Changes the parameter which controls whether or not~ boxes are drawn around the subviews.")) (defmethod get-menu-items :around ((self boxed-subview-mixin) (slot-name (eql 'middle-menu))) (if (box-views-menu-p self) (add-menu-items self '(("Boxes?" (set-box-views-p :toggle )) ) (call-next-method)) (call-next-method))) (defmethod update-menu-items :after ((self boxed-subview-mixin) (slot-name (eql 'middle-menu))) (let* ((m (slot-value self slot-name))) (if (box-views-menu-p self) (wb:check-menu-item m "Boxes?" (box-views-p self))) (if (box-color-menu-p self) (if (box-views-p self) (wb:enable-menu-item m "BoxColor") (wb:disable-menu-item m "BoxColor"))))) (defmethod set-box-views-p ((self boxed-subview-mixin) val &key (draw? t)) (if (eql val :toggle) (setq val (not (box-views-p self)))) (setf (box-views-p self) val) (if draw? (if val (draw-subview-boxes self) (erase-subview-boxes self)))) (defmethod draw-subview-boxes ((self boxed-subview-mixin) &key viewport) (let ((color (draw-style self :box-color)) (margin (subview-box-margin-of self))) (with-exposed-viewports self viewport vp (loop for sv in (subviews-of self) for sv-vp = (if sv (select-viewport sv vp)) when sv-vp do (draw-viewport sv-vp :color color :margin margin))))) (defmethod erase-subview-boxes ((self boxed-subview-mixin) &key viewport) (let ((margin (subview-box-margin-of self))) (with-exposed-viewports self viewport vp (loop for sv in (subviews-of self) for sv-vp = (if sv (select-viewport sv vp)) when sv-vp do (erase-viewport sv-vp :margin margin ))))) (defmethod draw-view :after ((self boxed-subview-mixin) &key viewport) (when (box-views-p self) (draw-subview-boxes self :viewport viewport))) (defmethod erase-view :after ((self boxed-subview-mixin) &key viewport) (when (box-views-p self) (erase-subview-boxes self :viewport viewport))) (defmethod reposition-view :after ((self boxed-subview-mixin) &key default-positions draw? ) (declare (ignore default-positions)) (when (and draw? (box-views-p self)) (draw-subview-boxes self))) ;;;---------------------------------------------------------------------------------- (defun bg-color-menu-items () (declare (special *color-menu-list* *shade-menu-list*)) (loop for c in (if (wb:color-device-p) *color-menu-list* *shade-menu-list*) collect (list (car c) `(set-drawing-style :bg-color ,(cadr c))))) (defmethod style-menu-items :around ((self bg-color-mixin)) (let ((result (call-next-method))) (if (bg-color-menu-p self) (add-menu-items self `(( "BGColor" nil "" :sub-items ,(bg-color-menu-items)) ) result) result))) (defmethod draw-view :before ((self bg-color-mixin) &key viewport) (if (has-draw-style-p self :bg-color) (let ((bg-color (draw-style self :bg-color))) (with-exposed-viewports self viewport vp (unless (wb:eq-colors bg-color (wb:canvas-background-color (window-of vp))) (fill-viewport vp :color bg-color)))))) ;;;---------------------------------------------------------------------------------- (defmethod get-draw-portion ((self square-view-mixin) viewport) (let ((square (copy-region viewport))) (setf (radius-of square) (radius-of viewport)) square)) (defmethod transform-mapping-draw-portions ((self square-view-mixin) region transform) (let ((new-region (apply-transform transform region))) (make-transform-for-regions (get-draw-portion self region) (get-draw-portion self new-region)) )) ;; the following methods xx-view ;; (with the exception of remove-view, which performs ;; surgery on the view hierarchy at a different level) ;; differ from the default xx-view in that ;; (i) if highlit? is non-nil the operation is applied only ;; to the highlighted subviews and ;(defclass pass-draws-to-subviews () ()) ;; already at line 59 20SEP2023 (defmethod styles-to-subs ((self pass-draws-to-subviews) ) (list :highlight?)) #| ;; comment these out because draw-view calls highlight if any subs are highlit. (defmethod all-highlight? ((self pass-draws-to-subviews)) (loop for v in (subviews-of self) for vis in (visible-subs-p self) always (or (not vis) (all-highlight? v)))) (defmethod any-highlight? ((self pass-draws-to-subviews)) (loop for v in (subviews-of self) for in? in (visible-subs-p self) thereis (and in? (any-highlight? v)))) |# (defmethod apply-to-subviews ((self pass-draws-to-subviews) fn viewport &optional highlit?) (loop for vp in (enlist-viewport self viewport) do (loop for sv in (some-subviews self :highlit? highlit?) for sv-vp = (select-viewport sv vp) do (funcall fn sv :viewport sv-vp :check-viewport? nil)))) (defmethod draw-view ((self pass-draws-to-subviews) &key viewport highlit?) (apply-to-subviews self #'draw-view viewport highlit?)) (defmethod invert-view ((self pass-draws-to-subviews) &key viewport highlit?) (apply-to-subviews self #'invert-view viewport highlit?)) (defmethod highlight-view ((self pass-draws-to-subviews) &key viewport ) (apply-to-subviews self #'highlight-view viewport )) (defmethod downlight-view ((self pass-draws-to-subviews) &key viewport ) (apply-to-subviews self #'downlight-view viewport )) (defmethod erase-view ((self pass-draws-to-subviews) &key viewport highlit?) (apply-to-subviews self #'erase-view viewport highlit? )) (defmethod get-viewed-obj-styles ((self styles-cache) &rest style-pairs ) ;; returns draw-styles in order of viewed-objects (setf (viewed-obj-styles-of self) (or (viewed-obj-styles-of self) (loop for vo in (cases-of self) collect (loop repeat (length (list-viewed-elements vo)) collect (apply #'default-drawing-style self style-pairs)))))) (defmethod compute-map-to-viewport((self flip-mixin) vp) (let* ((br (bounding-region-of self)) (tr (make-transform-for-regions br (get-draw-portion self vp)))) (if (or (flip-x-p self) (flip-y-p self)) (multiple-value-bind (l r b tp) (bounds-of br) (let ((x-scale (x-scale tr)) (y-scale (y-scale tr)) (x-shift (x-shift tr)) (y-shift (y-shift tr)) (sx 1) (sy 1) (ox 0) (oy 0)) (if (flip-x-p self) (setq sx -1 ox (* x-scale (+ l r)))) (if (flip-y-p self) (setq sy -1 oy (* y-scale (+ b tp)))) (translate-transform! tr (- x-shift) (- y-shift)) (scale-transform! tr sx sy) (translate-transform! tr (+ x-shift ox) (+ y-shift oy))))) tr)) (defmethod set-flip-x-p ((self flip-mixin) val &key (draw? nil ) ) (if (eq val :toggle) (setf val (not (flip-x-p self)))) (loop for v in (link-bounds-x-of self) do (if draw? (erase-view v)) (setf (flip-x-p v) val) (remap-to-viewports v :erase? nil :draw? draw?))) (defmethod set-flip-y-p ((self flip-mixin) val &key (draw? nil ) ) (if (eq val :toggle) (setf val (not (flip-y-p self)))) (loop for v in (link-bounds-y-of self) do (if draw? (erase-view v)) (setf (flip-y-p v) val) (remap-to-viewports v :erase? nil :draw? draw?))) ;;---------------------------------------------------------------------- (defmethod fix-viewports ((self view-with-size) &key viewport ) (let ((size (view-size-of self))) (loop for vp in (if viewport (list viewport) (viewports-of self) ) do (set-viewport-size vp size)))) (defmethod set-view-size ((self view-with-size) new &key (draw? t)) (if draw? (erase-view self)) (setf (view-size-of self) new) (fix-viewports self) (if draw? (draw-view self))) (defmethod set-view-size :around ((self view-with-size) new &key (draw? t)) (unless (numberp new) (setq new (get-view-size self new))) (call-next-method self new :draw? draw?)) (defmethod get-view-size ((self view-with-size) new) (let ((old (view-size-of self)) (inc (view-size-increment self))) (unless old (setq new :prompt)) (case new (:larger (+ old inc)) (:smaller (- old inc)) (:prompt (wb:prompt-user :result-type 'number :read-type :eval :prompt-string (format nil "Change size from ~A" old))) (t old)))) (defmethod view-size-increment ((self view-with-size)) (if (view-size-of self) (round (* (view-size-of self) 0.5)))) (defmethod reshape-viewport :after ((self view-with-size) viewport &rest ignore) ;; point symbol viewports are not resized when window is reshaped (declare (ignore ignore viewport)) (fix-viewports self)) (defmethod add-viewport :after ((self view-with-size) viewport pvp &key) (declare (ignore pvp)) (fix-viewports self :viewport viewport)) (defmethod get-menu-items :around ((self view-with-size) (slot-name (eql 'middle-menu))) (if (size-menu-p self) (let (( menu-list (call-next-method)) (size-menu-items '(("larger" (set-view-size :larger)) ("smaller" (set-view-size :smaller)) ("prompt" (set-view-size :prompt))))) (append menu-list `(( "Size" nil "" :sub-items ,size-menu-items) ))) (call-next-method))) ;;-------------------------------------------------------------------------------- (defmethod fix-viewports ((self fixed-size-rectangle) &key viewport ) (let ((h (rectangle-height-of self)) (w (rectangle-width-of self))) (loop for vp in (if viewport (list viewport) (viewports-of self) ) do (set-viewport-width-height vp (or w (width-of vp)) (or h (height-of vp)))))) (defmethod set-view-width ((self fixed-size-rectangle) w &key (draw? t)) (if draw? (erase-view self)) (setf (rectangle-width-of self) w) (fix-viewports self) (if draw? (draw-view self))) (defmethod set-view-height ((self fixed-size-rectangle) h &key (draw? t)) (if draw? (erase-view self)) (setf (rectangle-height-of self) h) (fix-viewports self) (if draw? (draw-view self))) (defmethod set-view-height :around ((self fixed-size-rectangle) h &key (draw? t)) (unless (numberp h) (setq h (get-view-height self h))) (call-next-method self h :draw? draw?)) (defmethod set-view-width :around ((self fixed-size-rectangle) w &key (draw? t)) (unless (numberp w) (setq w (get-view-width self w))) (call-next-method self w :draw? draw?)) (defmethod get-view-width ((self fixed-size-rectangle) new) (let ((old (rectangle-width-of self)) (inc (rectangle-width-increment self))) (unless old (setq new :prompt)) (case new (:larger (+ old inc)) (:smaller (- old inc)) (:prompt (wb:prompt-user :result-type 'number :read-type :eval :prompt-string (format nil "Change width from ~A" old))) (t old)))) (defmethod get-view-height ((self fixed-size-rectangle) new) (let ((old (rectangle-height-of self)) (inc (rectangle-height-increment self))) (unless old (setq new :prompt)) (case new (:larger (+ old inc)) (:smaller (- old inc)) (:prompt (wb:prompt-user :result-type 'number :read-type :eval :prompt-string (format nil "Change height from ~A" old))) (t old)))) (defmethod rectangle-height-increment ((self fixed-size-rectangle)) (let ((h (rectangle-height-of self)) vp) (cond ((not (null h)) (round (* h 0.5))) ((setq vp (car (viewports-of self))) ( round (* .5 (height-of vp)))) (t 1)))) (defmethod rectangle-width-increment ((self fixed-size-rectangle)) (let ((w (rectangle-width-of self)) vp) (cond ((not (null w)) (round (* w 0.5))) ((setq vp (car (viewports-of self))) ( round (* .5 (width-of vp)))) (t 1)))) (defmethod reshape-viewport :after ((self fixed-size-rectangle) viewport &rest ignore) ;; point symbol viewports are not resized when window is reshaped (declare (ignore ignore viewport)) (fix-viewports self)) (defmethod add-viewport :after ((self fixed-size-rectangle) viewport pvp &key) (declare (ignore pvp)) (fix-viewports self :viewport viewport)) (defmethod get-menu-items :around ((self fixed-size-rectangle) (slot-name (eql 'middle-menu))) (if (size-menu-p self) (let (( menu-list (call-next-method)) (width-menu-items '(("wider" (set-rectangle-width :larger)) ("narrower" (set-rectangle-width :smaller)) ("prompt" (set-rectangle-width :prompt)))) (height-menu-items '(("taller" (set-rectangle-width :larger)) ("shorter" (set-rectangle-height :smaller)) ("prompt" (set-rectangle-height :prompt))))) (append menu-list `(( "Width" nil "" :sub-items ,width-menu-items) ( "Height" nil "" :sub-items ,height-menu-items) ))) (call-next-method))) (defmethod set-rectangle-width ((self fixed-size-rectangle) new &key (draw? t)) (if draw? (erase-view self)) (setf (rectangle-width-of self) new) (fix-viewports self) (if draw? (draw-view self))) (defmethod set-rectangle-height ((self fixed-size-rectangle) new &key (draw? t)) (if draw? (erase-view self)) (setf (rectangle-height-of self) new) (fix-viewports self) (if draw? (draw-view self))) (defmethod set-rectangle-width :around ((self fixed-size-rectangle) new &key (draw? t)) (unless (numberp new) (setq new (get-view-width self new))) (call-next-method self new :draw? draw?)) (defmethod set-rectangle-height :around ((self fixed-size-rectangle) new &key (draw? t)) (unless (numberp new) (setq new (get-view-height self new))) (call-next-method self new :draw? draw?)) ;;-------------------------------------------------------------------------------- (defmethod delete-viewport :before ((self viewport-coords-cache-mixin) viewport) ;; remove the viewport VIEWPORT and corresponding MAP and PARENT-VIEWPORT (let ((temps (viewport-coords-cache-of self)) (p (position viewport (viewports-of self)))) (setf (viewport-coords-cache-of self) (delete (elt temps p) temps)))) (defmethod add-viewport :before ((self viewport-coords-cache-mixin) viewport pvp &key) (declare (ignore pvp)) (if (member viewport (viewports-of self)) (remove-viewport-coords self :viewport viewport) (push nil (viewport-coords-cache-of self)))) (defmethod viewport-coords-of ((self viewport-coords-cache-mixin) &key viewport) (setq viewport (or viewport (car (viewports-of self)))) (let ((p (position viewport (viewports-of self))) (temps (viewport-coords-cache-of self)) (meth (viewport-compute-method-of self))) (or (elt temps p) (setf (elt temps p) (if meth (funcall meth self viewport)))))) (defmethod set-bounding-region :after ((self viewport-coords-cache-mixin) &key &allow-other-keys) (remove-viewport-coords self)) (defmethod remove-viewport-coords ((self viewport-coords-cache-mixin) &key viewport) (if viewport (let ((p (position viewport (viewports-of self)))) (setf (elt (viewport-coords-cache-of self) p) nil)) (setf (viewport-coords-cache-of self) (make-list (length (viewports-of self)))))) (defmethod reshape-viewport :after ((self viewport-coords-cache-mixin) viewport &key new-location transform draw? ) (declare (ignore new-location transform draw? )) (remove-viewport-coords self :viewport viewport) ) (defmethod set-viewport-coords ((self viewport-coords-cache-mixin) &key viewport coords ) (let ((p (position viewport (viewports-of self))) (temps (viewport-coords-cache-of self)) ) (setf (elt temps p) coords))) (defclass viewed-elements-mixin () ((viewed-elements :initform :viewed-object :accessor viewed-elements-of :initarg :viewed-elements :documentation "Cache for list of elements in object being viewed") )) #| Use of viewed-elements-mixin: multi-style-views have one drawing style per viewed element. linkable-views: views with common (as determined by the link test) viewed-elements are linked viewed-elements = :single regard viewed object as a single viewed element (eg data-label) viewed-elements = :expand-viewed-object list-viewed-elements returns (list-viewed-elements viewed-object) (eg group-label) initial viewed-elements = function list-viewed-elements returns the fuinction applied to the viewed object initial viewed-elements = viewed object list-viewed-elements returns the viewed object as a list. the default |# (defmethod list-viewed-elements ((self viewed-elements-mixin)) (let ((vo-elt (viewed-elements-of self))) (if (listp vo-elt) vo-elt (let ((vo (viewed-object-of self))) (setf (viewed-elements-of self) (cond ((eq vo-elt :single) (if (null vo) vo (list vo))) ((eq vo-elt :viewed-object) (if (or (null vo) (list-of-datasets-p vo)) vo (list vo))) ((eq vo-elt :expand-viewed-object) (cond ((null vo) vo) ((dataset-p vo) (list-cases vo)) (t (list vo)))) ((functionp vo-elt) (funcall vo-elt self)) (t nil))))))) (defmethod list-viewed-elements ((vo t)) (cond ((dataset-p vo) (list-cases vo)) (t (list vo))))
32,766
Common Lisp
.l
686
37.696793
134
0.578103
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d51a20bc43366a0c752fab3ffe039c4a1688ce94d0bb62ce39c6a9af95916e59
33,183
[ -1 ]
33,184
tic-mixin.lsp
rwoldford_Quail/source/views/views-mixins/tic-mixin.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; tic-mixin.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical ;;; graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; Originator: J.O. Pedersen 1985 ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(tic-mixin ))) (defclass tic-mixin () ((format :accessor tic-format-of :initform nil :initarg :tic-format) (tic-interval :accessor tic-interval-of :initform nil ) (ntics :initform (default-ntics) :initarg :ntics :accessor ntics-of ) (tic-info :accessor tic-info-of :initform nil ) (tic-list :initarg :tic-list :initform nil) (internal-tics? :accessor internal-tics-p :initform nil :initarg :internal-tics?))) (defun default-ntics () '(2 3 4 5 6 7 8)) (defun make-tic-info (&key (min 0.0) (max 1.0) (ntics 2) (increment 1.0)) (list min max ntics increment)) (defmacro tic-min (ti) `(elt ,ti 0)) (defmacro tic-max (ti) `(elt ,ti 1)) (defmacro tic-inc (ti) `(elt ,ti 3)) (defmacro ntics (ti) `(elt ,ti 2)) (defun tic-interval-len (ti) (- (tic-max ti) (tic-min ti))) (defmethod set-bounding-region :after ((self tic-mixin) &key (pretty? t) ignore-x? ignore-y? interval min max &allow-other-keys ) (let ((dir (axis-of-orientation self))) (unless (or (and ignore-x? (eq dir :x)) (and ignore-y? (eq dir :y))) (setf (internal-tics-p self) (not pretty?)) (if (and min max) (setf (extent-of self) (list min max))) (if interval (setf (extent-of self) interval)) (get-tic-interval self) (if pretty? (expand-extent self (tic-interval-of self)))))) (defmethod get-tic-interval ((self tic-mixin) &optional min max) (let (emin emax) (unless (and min max) (multiple-value-setq (emin emax) (extent-of self))) (setq min (or min emin)) (setq max (or max emax)) (let ((ti (tic-interval-of self)) (tinf (slot-value self 'tic-info))) (if (and ti tinf (= min (tic-min ti)) (= max (tic-max ti))) ti (progn (choose-tics self min max) (choose-scale self min max)))))) (defmethod choose-tics ((self tic-mixin) min max) (setf (tic-info-of self) (if (internal-tics-p self) (internal-tic-fn self min max ) (tic-fn self min max )))) (defmethod choose-scale ((self tic-mixin) min max) (setf (tic-interval-of self) (scale-fn self min max))) (defmethod scale-fn ((self tic-mixin) min max) (declare (ignore min max)) (let ((ti (tic-info-of self))) (make-interval (tic-min ti) (tic-max ti)))) (defmethod tic-fn ((self tic-mixin) min max &optional (tics (ntics-of self))) (if (integerp tics) (setq tics (list tics))) (loop with shortest = (scale-axis min max (first tics)) for ntics in (cdr tics) for current = (scale-axis min max ntics ) when (< (tic-interval-len current) (tic-interval-len shortest)) do (setq shortest current) finally (return shortest))) (defun internal-scale-axis (min max ntics) (let* ((c (scale-axis min max (+ 2 ntics))) (tinc (tic-inc c))) (loop while (< (tic-min c) min) do (incf (tic-min c) tinc) (decf (ntics c) 1)) (loop while (> (tic-max c) max) do (decf (tic-max c) tinc) (decf (ntics c) 1)) c)) (defmethod internal-tic-fn ((self tic-mixin) min max &optional (tics (ntics-of self))) (if (integerp tics) (setq tics (list tics))) (loop with longest = (internal-scale-axis min max (first tics)) for ntics in (cdr tics) for c = (internal-scale-axis min max ntics ) do (if (> (tic-interval-len c) (tic-interval-len longest)) (setq longest c)) finally (return longest))) (defun scale-axis ( min max ntics &optional (round ;; Rounding Constants. Notice that they are ;; in decreasing order and end with 1.0 '(5.0 2.5 2.0 1.5 1.0)) power) "Scaling algorithm for plots. NTICS is the desired number of ~ tics. Round is a list of acceptable scaling factors. POWER ~ is the power of ten to use. Returns a TICINFO including ~ NEWMAX, NEWMIN, INC, and NTICS." (when (= min max) (cond ((minusp max) (setf min (* 1.1 min)) (setf max (* 0.9 max))) ((zerop max) (setf min -1) (setf max 1)) (T (setf min (* 0.9 min)) (setf max (* 1.1 max))) ) ) (if (and (< min 0) (> max 0) (= ntics 2)) ;; failure of this algorithm!! ch (scale-axis2 min max round) (let* ((n-inc (1- ntics)) (raw-inc (/ (float (- max min)) n-inc)) mantissa index) ;; POWER is the power of ten (setq power (expt 10.0 (or power (floor (log raw-inc 10.0))))) ;; MANTISSA is the scale factor (setq mantissa (/ raw-inc power)) (if (> mantissa (first round)) (setq power (* 10.0 power) index (last round)) (setq index (do ((mark round (cdr mark))) ((null (cdr mark)) mark) (if (> mantissa (second mark)) (return mark))))) ;; Find new max and new min (let ((new-max min) new-min inc factor lower-mult upper-mult) (loop (unless (< new-max max) (return (make-tic-info :min new-min :max new-max :increment inc :ntics ntics))) (setq inc (* (first index) power)) (setq factor (/ (- (+ max min) (* n-inc inc)) (* 2.0 inc))) (setq new-min (* inc (setq lower-mult (ceiling factor)))) (if (> new-min min) (setq new-min (* inc (setq lower-mult (1- lower-mult)) ))) (if (and (>= min 0.0) (minusp new-min)) (setq lower-mult 0 new-min 0.0)) (setq upper-mult (+ lower-mult n-inc)) (setq new-max (* inc upper-mult)) (if (and (<= max 0.0) (> new-max 0.0)) (setq upper-mult 0 new-max 0.0 lower-mult (- n-inc) new-min (* inc lower-mult))) (if (eq round index) (setq index (last round) power (* 10.0 power)) (setq index (do ((mark round (cdr mark))) ((eq (cdr mark) index) mark))))) )))) (defun scale-axis2(min max round) (loop with newmin and newmax and wmin and wmax for r in round for i upfrom 0 do (setq newmin (* r (floor min r))) (setq newmax (* r (ceiling max r))) (if (or (null wmin) (<= 0 (- newmax newmin) (- wmax wmin))) (setq wmin newmin wmax newmax)) finally (return (make-tic-info :min wmin :max wmax :increment (- wmax wmin) :ntics 2)))) (defmethod tic-info-of :before ((self tic-mixin)) (unless (slot-value self 'tic-info) (get-tic-interval self))) (defmethod (setf tic-list-of) (new-val (self tic-mixin) ) (setf (slot-value self 'tic-list) new-val)) (defmethod tic-list-of ((self tic-mixin) ) "Returns the tic list based on values of tic-info." (or (slot-value self 'tic-list) (let* ((tic-info (tic-info-of self)) (ticinc (tic-inc tic-info))) (etypecase ticinc (list ticinc) (number (append (do ((i 1 (+ i 1)) (x (tic-min tic-info) (+ x ticinc)) (result nil (push x result))) ((>= i (ntics tic-info)) (nreverse result))) (list (tic-max tic-info)))))))) #| (defmethod get-tic-list ((self tic-mixin)) (unless (tic-info-of self) (get-tic-interval self)) (let ((tm (tic-method-of self))) (if (listp tm) tm (funcall tm self)))) ;;; old (defun normalize-tic-list (tic-list &optional format (orientation :horizontal) (justification :bottom)) (mapcar #'(lambda (tic) (let (value label) (if (listp tic) (setq value (car tic) label (cadr tic)) (setq value (setq label tic))) (cons value (if (numberp label) (float-to-string label format orientation justification) label)))) tic-list)) (defun float-to-string (x &optional format (orientation :horizontal) (justification :bottom)) (if (= x (truncate x)) (setq x (truncate x))) (cond (format (format NIL format x)) (T (setf format (let ((abs-x (abs x))) (cond ((zerop abs-x) (format nil "~6,,,D" x)) ((or (< abs-x 0.001) (>= abs-x 1.0E+7)) (format nil "~6,3,,E" x)) (t (format nil "~6,2,,F" x))))) (if (or (eq orientation :horizontal) (not (eq justification :right))) (string-left-trim '(#\Space) format) format) ) ) ) |# (defun normalize-tic-list (tic-list &optional format (orientation :horizontal) (justification :bottom)) (let ((default-format :decimal) normalized-tic-list ) (cond ((stringp format) (setf normalized-tic-list (mapcar #'(lambda (tic) (let (value label) (if (listp tic) (setq value (car tic) label (cadr tic)) (setq value (setq label tic))) (cons value (if (numberp label) (format NIL format (if (= label (truncate label)) (truncate label) label)) label)))) tic-list))) (T ;; nice default format (setf format "~6,,,D") ;; collect up list and determine the best format to boot. (setf normalized-tic-list (mapcar #'(lambda (tic) (let (value label abs-x) (if (listp tic) (setq value (car tic) label (cadr tic)) (setq value tic label tic)) ;; See if format should be changed (when (numberp label) (setf abs-x (abs label)) (cond ((= label (truncate label)) (setq label (truncate label)) (when (> label 1.0E7) (setf default-format :exponential) (setf format "~6,3,,E") ) ) (T (if (not (eq default-format :exponential)) (cond ((or (< abs-x 0.001) (>= abs-x 1.0E+7)) (setf default-format :exponential) (setf format "~6,3,,E")) ((eq default-format :decimal) (setq default-format :Fixed-floating) (setq format "~6,2,,F")))) ))) (cons value label))) tic-list)) (if (or (eq orientation :horizontal) (not (eq justification :right))) ;; trim leading space off each label (setf normalized-tic-list (mapcar #'(lambda (tic) (let (value label) (setq value (car tic) label (cdr tic)) ;; Fix label if number (if (numberp label) (setf label (string-left-trim '(#\Space) (format NIL format label)) ) ) (cons value label))) normalized-tic-list)) ;; Run as plain (setf normalized-tic-list (mapcar #'(lambda (tic) (let (value label) (setq value (car tic) label (cdr tic)) ;; Fix label if number (if (numberp label) (setf label (format NIL format label)) ) (cons value label))) normalized-tic-list)) ) ) ) normalized-tic-list) ) ;;; ;;; Note that there is now one of these for axis as well. ;;; to take advantage of the justification (defmethod tic-list-for-viewport ((self tic-mixin) vp ) (let* ((orientation (orientation-of self)) (tic-list (normalize-tic-list (tic-list-of self) (tic-format-of self) orientation )) (map (select-map-to-viewport self vp) ) offset scale min max) (if (eql orientation :horizontal) (setf offset (x-shift map) scale (x-scale map) min (left-of vp) max (right-of vp)) (setf offset (y-shift map) scale (y-scale map) min (bottom-of vp) max (top-of vp))) (loop for tic in tic-list for tic-pos-vp = (round (+ offset (* scale (car tic)))) when (and (>= tic-pos-vp (- min 2)) (<= tic-pos-vp (+ 2 max))) collect (cons tic-pos-vp (cdr tic)))))
15,667
Common Lisp
.l
370
27.224324
86
0.449558
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e930973df4debbba395d8dc2c01fdb014be88da63d4fa19341e9f735722989f2
33,184
[ -1 ]
33,185
draw-macros.lsp
rwoldford_Quail/source/views/views-macros/draw-macros.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; draw-macros.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(with-exposed-viewports enlist-viewport with-bordered-plot-subs with-update-style-cache))) (defmacro with-point-symbol-center&radius ( point-sym vp xc yc rad &body do-forms) (let ((c (gensym)) (s (gensym))) `(let* ((,s (draw-style ,point-sym :size)) (,c (centre-of ,vp))) (setq ,rad (truncate ,s 2)) (setq ,xc (2d-position-x ,c)) (setq ,yc (2d-position-y ,c)) ,@do-forms))) (defmacro with-point-symbol-bounds (point-sym vp xmin xmax ymin ymax &body do-forms) (let ((c (gensym "c")) (xc (gensym "xc")) (yc (gensym "yc")) (size (gensym "size")) (rad (gensym "rad"))) `(let* ((,size (draw-style ,point-sym :size)) (,c (centre-of ,vp)) (,xc (2d-position-x ,c)) (,yc (2d-position-y ,c)) (,rad (truncate ,size 2))) (setq ,xmin (- ,xc ,rad)) (setq ,xmax (+ ,xmin ,size)) (setq ,ymin (- ,yc ,rad)) (setq ,ymax (+ ,ymin ,size)) ,@do-forms))) (defmacro enlist-viewport (view viewport) `(if ,viewport (if (listp ,viewport) ,viewport (list ,viewport)) (viewports-of ,view))) #| (defmacro with-exposed-viewports ( view viewport vp &body do-forms) `(dolist (,vp (mapcar #'(lambda(x) (get-draw-portion ,view x)) (if ,viewport (if (listp ,viewport) ,viewport (list ,viewport)) (viewports-of ,view)))) (when (active-viewport-p ,vp) ,@do-forms))) |# (defmacro with-exposed-viewports ( view viewport vp &body do-forms) `(if (and ,viewport (not (listp ,viewport))) (if (active-viewport-p ,viewport) (let ((,vp (get-draw-portion ,view ,viewport))) ,@do-forms)) (dolist (,vp (mapcar #'(lambda(x) (get-draw-portion ,view x)) (or ,viewport (viewports-of ,view)))) (when (active-viewport-p ,vp) ,@do-forms)))) (defmacro with-bordered-plot-subs (plot interior-view left-view right-view bottom-view top-view left-label right-label bottom-label top-label &body do-forms) `(let ((,left-view (left-views-of ,plot)) (,right-view (right-views-of ,plot)) (,top-view (top-views-of ,plot)) (,bottom-view (bottom-views-of ,plot)) (,interior-view (interior-views-of ,plot)) (,left-label (left-labels-of ,plot)) (,right-label (right-labels-of ,plot)) (,top-label (top-labels-of ,plot)) (,bottom-label (bottom-labels-of ,plot)) ) ,@do-forms)) (defvar *update-style-cache* nil) (defvar *cache-updates?* nil) (setq *update-style-cache* nil) (setq *cache-updates?* nil) (defmacro optional-cache(form) "When *cache-updates?* is non nil, certain calls to ~ draw-view, erase-view, highlight-view and downlight-view ~ are cached, rather than being performed right away. " (let((oldpair (gensym "opt-cache-oldpair")) (old (gensym "opt-cache-old")) (new (gensym "opt-cache-new")) (view (gensym "opt-cache-view"))) `(let() (declare (special *update-style-cache* *cache-updates?*)) (if *cache-updates?* (let ((,view ,(second form))) (when (active-viewports-p ,view) (let* ( (,oldpair (assoc ,view *update-style-cache*)) (,old (cdr ,oldpair)) (,new (function ,(first form)))) (cond ((null ,oldpair) (setq *update-style-cache* (acons ,view ,new *update-style-cache*))) ((null ,old) (setf (cdr ,oldpair) ,new)) ((eql ,new ,old) nil) ((eql ,old #'erase-view) (setf (cdr ,oldpair) #'draw-view)) ((eql ,new #'erase-view) (setf (cdr ,oldpair) #'erase-view)) ((eql ,old #'draw-view) nil) ((eql ,new #'draw-view) (setf (cdr ,oldpair) #'draw-view)) ;; ((not (typep ,view 'multiple-draw-style-mixin)) ;; (setf (cdr ,oldpair) nil)) (t (setf (cdr ,oldpair) #'draw-view))) nil))) ,form)))) (defmacro with-update-style-cache(&body forms) "Certain calls to draw-view, erase-view, ~ highlight-view and downlight-view within forms~ are delayed. This means that multiple draws on a ~ view are effected with a single draw." `(let() (declare (special *update-style-cache* *cache-updates?*)) (if (null *cache-updates?*) (progn (unwind-protect (progn (setq *cache-updates?* t) ,@forms (loop for (view . action) in *update-style-cache* when action do ;; safer to put downlight in here because of the boole-xor drawing (if (or (eql action #'draw-view) (and (or (eql action #'downlight-view) (eql action #'highlight-view)) (eql (highlight-operation view) :boole-xor))) (draw-view view :erase? t) (funcall action view)))) (setq *cache-updates?* nil) (setq *update-style-cache* nil))) (progn ,@forms))))
6,778
Common Lisp
.l
157
30.394904
106
0.471158
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4f1e1f9df09839ca7949fe2b32a0a35c9d8adcb015a92eafcf668abdd4fe8520
33,185
[ -1 ]
33,186
region.lsp
rwoldford_Quail/source/views/views-macros/region.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; region.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( make-interval interval-p min-of max-of length-of make-2d-position 2d-position-x ;;(setf 2d-position-x) 2d-position-y ;;(setf 2d-position-y) 2d-position-p left-of right-of bottom-of top-of ;;( setf left-of) ( setf right-off) ( setf bottom-of) ( setf top-of) height-of width-of radius-of region-p make-region window-of ;;(setf window-of ) viewport-p make-viewport window-of bounds-of ;;( setf bounds-of ) x-extent-of y-extent-of maximize-regions bottom-left-of bottom-right-of top-left-of top-right-of centre-of contains-p coerce-bounds-to-integer distance-from intersects-p make-transform-for-regions map-region scale-sides-by shift-by sub-region tile-region tile-region-list wb-region wb-position view-region view-position set-viewport-width-height set-square-region-center copy-region set-square-viewport-size active-viewport-p activate-viewport deactivate-viewport valid-region-check))) ;;;---------------------------------------------------------------------------------- (defmacro make-interval (&optional (x 0) (y 0)) `(vector ,x ,y)) (defmacro interval-p (x) `(and (vectorp ,x) (= 2 (length ,x)))) (defmacro min-of (interval) `(svref ,interval 0)) (defmacro max-of (interval) `(svref ,interval 1)) (defsetf min-of (interval) (new-min) `(setf (svref ,interval 0) ,new-min)) (defsetf max-of (interval) (new-max) `(setf (svref ,interval 1) ,new-max)) (defmacro length-of (interval) `(- (max-of ,interval) (min-of ,interval))) ;;================================================================= (defmacro make-2d-position (&optional (x 0) (y 0)) `(vector ,x ,y)) (defmacro 2d-position-x (position) `(svref ,position 0)) (defmacro 2d-position-y (position) `(svref ,position 1)) (defsetf 2d-position-x (position) (new-x) `(setf (svref ,position 0) ,new-x)) (defsetf 2d-position-y (position) (new-y) `(setf (svref ,position 0) ,new-y)) (defmacro 2d-position-p (x) `(and (vectorp ,x) (= 2 (length ,x)))) ;;================================================================= ;;; Regions are stored as left right bottom top. (defmacro left-of (region) `(svref ,region 1)) (defmacro right-of (region) `(svref ,region 2)) (defmacro bottom-of (region) `(svref ,region 3)) (defmacro top-of (region) `(svref ,region 4)) (defsetf left-of (region) (new) `(setf (svref ,region 1) ,new)) (defsetf right-of (region) (new) `(setf (svref ,region 2) ,new)) (defsetf bottom-of (region) (new) `(setf (svref ,region 3) ,new)) (defsetf top-of (region) (new) `(setf (svref ,region 4) ,new)) (defmacro height-of (region) `(- (top-of ,region) (bottom-of ,region))) (defmacro width-of (region) `(- (right-of ,region) (left-of ,region))) (defsetf width-of (region) (new-width) (let ((c (gensym)) (cx (gensym)) ) `(let* ((,c (centre-of ,region)) (,cx (2d-position-x ,c)) ) (setf (left-of ,region) (- ,cx (/ ,new-width 2))) (setf (right-of ,region) (+ ,cx (/ ,new-width 2)))))) (defsetf height-of (region) (new-height) (let ((c (gensym)) (cy (gensym)) ) `(let* ((,c (centre-of ,region)) (,cy (2d-position-y ,c)) ) (setf (bottom-of ,region) (- ,cy (/ ,new-height 2))) (setf (top-of ,region) (+ ,cy (/ ,new-height 2)))))) (defmacro region-p (r) `(and (vectorp ,r) (or (eql (svref ,r 0) 'region) (eql (svref ,r 0) 'viewport)))) (eval-when (:compile-toplevel :load-toplevel :execute) (proclaim '(inline make-region))) (defun make-region (&optional (b1 0.0) (b2 1.0) (b3 0.0) (b4 1.0)) (if (region-p b1) (multiple-value-setq (b1 b2 b3 b4) (bounds-of b1))) (vector 'region b1 b2 b3 b4)) ;;;================================================================= ;;; viewports are regions on windows (defmacro window-of (viewport) `(svref ,viewport 5)) (defsetf window-of (viewport) (window) `(setf (svref ,viewport 5), window)) (defmacro active-viewport-p (viewport) `(and (wb:canvas-visible-p (svref ,viewport 5) ) (svref ,viewport 6))) (defmacro deactivate-viewport (viewport) `(setf (svref ,viewport 6) nil)) (defmacro activate-viewport (viewport) `(setf (svref ,viewport 6) t)) (defmacro viewport-p (r) `(and (vectorp ,r) (eql (svref ,r 0) 'viewport))) ;;================================================================= (eval-when (:compile-toplevel :load-toplevel :execute) (proclaim '(inline bounds-of))) (defun bounds-of (region) (values (left-of region) (right-of region) (bottom-of region) (top-of region))) (eval-when (:compile-toplevel :load-toplevel :execute) (proclaim '(inline valid-region-check))) (defun valid-region-check(region &optional (signal-error? t )) (multiple-value-bind (l r b tp) (bounds-of region) (if (or (>= l r) (>= b tp)) (if signal-error? (quail-error "Region with bounds ~F,~F,~F,~F is invalid" l r b tp) nil) t))) (defsetf bounds-of (region) (bounds) ;;; sets bounds of REGION to BOUNDS ;;; BOUNDS is a REGION or a list in order left, right bottom top (let ((l (gensym)) (r (gensym)) (b (gensym)) (tp (gensym))) `(multiple-value-bind (,l ,r ,b ,tp) (if (region-p ,bounds) (bounds-of ,bounds) (values-list ,bounds)) (setf (left-of ,region) ,l) (setf (right-of ,region) ,r) (setf (top-of ,region) ,tp) (setf (bottom-of ,region) ,b) (if (viewport-p ,region) (coerce-bounds-to-integer ,region))))) (defsetf x-extent-of (region) (bounds) ;;; sets x extent of REGION to BOUNDS ;;; BOUNDS is a REGION or a list in order left, right (let ((l (gensym)) (r (gensym)) ) `(multiple-value-bind (,l ,r ) (if (region-p ,bounds) (bounds-of ,bounds) (values-list ,bounds)) (setf (left-of ,region) ,l) (setf (right-of ,region) ,r) (if (viewport-p ,region) (coerce-bounds-to-integer ,region))))) (defsetf y-extent-of (region) (bounds) ;;; sets y extent of REGION to BOUNDS ;;; BOUNDS is a REGION or a list in order bottom top (let ( (b (gensym)) (tp (gensym)) (ignore-left (gensym)) (ignore-right (gensym))) `(multiple-value-bind (,ignore-left ,ignore-right ,b ,tp) (if (region-p ,bounds) (bounds-of ,bounds) (values-list (append '(nil nil) ,bounds))) (declare (ignore ,ignore-left ,ignore-right)) (setf (top-of ,region) ,tp) (setf (bottom-of ,region) ,b) (if (viewport-p ,region) (coerce-bounds-to-integer ,region))))) (defun maximize-regions (region &rest regions) ;; returns the smallest region enclosing region (loop for r in (push region regions) maximize (top-of r) into top minimize (bottom-of r) into bottom maximize (right-of r) into right minimize (left-of r) into left finally (return (make-region left right bottom top) ))) (eval-when (:compile-toplevel :load-toplevel :execute) (proclaim '(inline bottom-left-of bottom-right-of top-left-of top-right-of centre-of coerce-bounds-to-integer distance-from))) (defun bottom-left-of (region) ;;; return the POSITON coresponding to bottom-left of region (make-2d-position (left-of region) (bottom-of region))) (defun bottom-right-of (region) ;; return the POSITON coresponding to bottom-right of REGION (make-2d-position (right-of region) (bottom-of region))) (defun top-left-of (region) ;; return the POSITON coresponding to top-left of REGION (make-2d-position (left-of region) (top-of region))) (defun top-right-of (region) ;; return the POSITON coresponding to top-right of REGION (make-2d-position (right-of region) (top-of region))) (defun centre-of ( region) ;; return the POSITON coresponding to center of region (multiple-value-bind (l r b tp) (bounds-of region) (if (viewport-p region) (make-2d-position (truncate (+ l r) 2) (truncate (+ b tp) 2)) (make-2d-position (/ (+ l r) 2) (/ (+ b tp) 2))))) (defmethod contains-p ((region t) z) ;; returns REGION when it contains Z (a 2d-position or a region) (if (2d-position-p z) (multiple-value-bind (l r b tp) (bounds-of region) (when (and (>= (2d-position-x z) l) (<= (2d-position-x z) r) (>= (2d-position-y z) b) (<= (2d-position-y z) tp)) region)) (if (region-p z) (multiple-value-bind (l r b tp) (bounds-of region) (multiple-value-bind (l1 r1 b1 tp1) (bounds-of z) (when (and (>= l1 l) (<= r1 r) (>= b1 b) (<= tp1 tp)) region)))))) (defun coerce-bounds-to-integer (region) (multiple-value-bind (l r b tp) (bounds-of region) (setf (left-of region) (truncate l)) (setf (right-of region) (truncate r)) (setf (bottom-of region) (truncate b)) (setf (top-of region) (truncate tp)))) (defun distance-from (region point) ;; returns distance-from regions centre to POINT (let ((c (centre-of region))) (max (abs (- (2d-position-x c) (2d-position-x point))) (abs (- (2d-position-y c) (2d-position-y point)))))) (defmethod intersects-p ((region1 t) (region2 t)) ;;; returns non NIL IF REGION1 intersects REGION2 (multiple-value-bind (la ra ba ta) (bounds-of region1) (multiple-value-bind (lb rb bb tb) (bounds-of region2) (and (<= (max la lb) (min ra rb)) (<= (max ba bb) (min ta tb)))))) #| (defun make-transform-for-regions (from-region to-region) ;;; returns a 2D-AFFINE mapping FROM-REGION to TO-REGION (multiple-value-bind (l r b tp) (bounds-of from-region) (multiple-value-bind (l1 r1 b1 tp1) (bounds-of to-region) (let* ((tr (make-affine-transform 2)) (w1 (- r l)) (w2 (- r1 l1)) (h1 (- tp b)) (h2 (- tp1 b1)) (x-slope (if (zerop w1) 1 (/ w2 w1))) (y-slope (if (zerop h1) 1 (/ h2 h1))) (x-intercept (if (zerop w1) (- (/ (+ l1 r1) 2) l) (/ (- (* r l1) (* r1 l)) w1))) (y-intercept (if (zerop h1) (- (/ (+ b1 tp1) 2) b) (/ (- (* tp b1) (* tp1 b)) h1)))) (scale-transform! tr x-slope y-slope) (translate-transform! tr x-intercept y-intercept) tr)))) |# (defun make-transform-for-regions (from-region to-region) ;;; returns a 2D-AFFINE mapping FROM-REGION to TO-REGION (multiple-value-bind (l r b tp) (bounds-of from-region) (multiple-value-bind (l1 r1 b1 tp1) (bounds-of to-region) (let* ((tr (make-affine-transform 2)) (w1 (- r l)) (w2 (- r1 l1)) (h1 (- tp b)) (h2 (- tp1 b1)) (x-slope (if (or (zerop w1) (zerop w2)) 0 (/ w2 w1))) (y-slope (if (or (zerop h1) (zerop h2)) 0 (/ h2 h1))) (x-intercept (if (or (zerop w1) (zerop w2)) (+ l1 (/ w2 2)) (/ (- (* r l1) (* r1 l)) w1))) (y-intercept (if (or (zerop h1) (zerop h2)) (+ b1 (/ h2 2)) (/ (- (* tp b1) (* tp1 b)) h1)))) (scale-transform! tr x-slope y-slope) (translate-transform! tr x-intercept y-intercept) tr)))) (defun map-region (self from-region to-region) ;; compute the affine transform mapping from-region into to-region ;; and apply it to self, returning the result (apply-transform (make-transform-for-regions from-region to-region) self)) (eval-when (:compile-toplevel :load-toplevel :execute) (proclaim '(inline radius-of))) (defun radius-of (region) ;;; returns min of width and height times .5 (/ (min (height-of region) (width-of region)) 2)) (defsetf radius-of (region) (new-radius) (let ((c (gensym)) (cx (gensym)) (cy (gensym))) `(let* ((,c (centre-of ,region)) (,cx (2d-position-x ,c)) (,cy (2d-position-y ,c))) (setf (bounds-of ,region) (list (- ,cx ,new-radius) (+ ,cx ,new-radius) (- ,cy ,new-radius) (+ ,cy ,new-radius))) ,new-radius))) (defun scale-sides-by (region &optional (x-factor 1) (y-factor 1)) ;;; multiplies width and height of REGION by X-FACTOR and Y-FACTOR ;;; respectively. (let* ((w/2 (/ (* (width-of region) x-factor) 2)) (h/2 (/ (* (height-of region) y-factor) 2)) (c (centre-of region)) (cx (2d-position-x c)) (cy (2d-position-y c))) (setf (bounds-of region) (list (- cx w/2) (+ cx w/2) (- cy h/2) (+ cy h/2))) region)) (defun shift-by (region &optional (x-shift 0) (y-shift 0)) ;;; shifts REGION right by x and up by y (incf (left-of region) x-shift) (incf (right-of region) x-shift) (incf (bottom-of region) y-shift) (incf (top-of region) y-shift) region) (defun sub-region (big-region position &key (width (width-of big-region)) (height (height-of big-region)) (mid-pt (if (or (eql position :n) (eql position :s)) (2d-position-x (centre-of big-region)) (2d-position-y (centre-of big-region))) ) remains) ;;; returns a REGION in BIG-REGION at position (:n :s :e :w), ;; with dimenions WIDTH * HEIGHT, centered at mid-pt (let (new-region (wid/2 (* 0.5 width)) (hgt/2 (* 0.5 height))) (multiple-value-bind (l r b tp) (bounds-of big-region) (if remains (setf (bounds-of remains) (list l r b tp))) (ecase position (:n (setf new-region (make-region (- mid-pt wid/2) (+ mid-pt wid/2) (- tp height) tp )) (if remains (setf (top-of remains) (bottom-of new-region)))) (:s (setf new-region (make-region (- mid-pt wid/2) (+ mid-pt wid/2) b (+ b height))) (if remains (setf (bottom-of remains) (top-of new-region)))) (:e (setf new-region (make-region (- r width) r (- mid-pt hgt/2) (+ mid-pt hgt/2))) (if remains (setf (right-of remains) (left-of new-region)))) (:w (setf new-region (make-region l (+ l width) (- mid-pt hgt/2) (+ mid-pt hgt/2))) (if remains (setf (left-of remains) (right-of new-region)))))) new-region) ) (defun tile-region (region nrows ncols &optional square? (gap-x 0) (gap-y 0)) "Returns a list where each list element is a list~ of regions in a row beginning at the top-left,~ separated in the horizontal direction by gap-x and by gap-y in~ the vertical direction.~ If square? is non-nil the regions created are square." (let* ((w (/ (width-of region) (+ (* (- ncols 1 ) gap-x) ncols))) (h (/ (height-of region) (+ (* (- nrows 1 ) gap-y) nrows)))) (setq gap-x (* gap-x w)) (setq gap-y (* gap-y h)) (if square? (setq w (min w h) h w)) (multiple-value-bind (l r b tp) (bounds-of region) (loop for i from 0 below nrows collect (loop for j from 0 below ncols collect (make-region (+ l (* j w) (* j gap-x)) (min r (+ l (* (1+ j) w) (* j gap-x))) (max b (- tp (* (1+ i) h) (* i gap-y))) (- tp (* i h) (* i gap-y))) ))))) (defun tile-region-list (region nrows ncols &optional square? (gap-x 0) (gap-y 0)) "Returns a list of sub regions of region with nrows rows and ncols ~ columns, separated in the horizontal direction by gap-x and by gap-y in~ the vertical direction.~ If square? is non-nil the regions created are square." (reduce #'append (tile-region region nrows ncols square? gap-x gap-y))) ;;;================================================================= (defun make-viewport (&optional (w (make-view-window)) (xmin 0.0) (xmax 1.0) (ymin 0.0) (ymax 1.0)) "Makes a VIEWPORT in the window w having bounds given by xmin xmax ymin ymax. ~ These may be in window coordinates or in 0-1 coords." (setq w (if (typep w 'view-window) w (make-view-window :title w))) (multiple-value-setq (xmin xmax ymin ymax) (if (region-p xmin) (bounds-of xmin) ;;else (case xmin (left (values 0.0 0.49 0.0 1.0)) (right (values 0.51 1.0 0.0 1.0)) (bottom (values 0.0 1.0 0.0 0.49)) (top (values 0.0 1.0 0.51 1.0)) (top-left (values 0.0 0.49 0.51 1.0)) (top-right (values 0.51 1.0 0.51 1.0)) (bottom-left (values 0.0 0.49 0.0 0.49)) (bottom-right (values 0.51 1.0 0.0 0.49)) (t (values xmin xmax ymin ymax))))) (let* ((vp (vector 'viewport nil nil nil nil nil t)) (reg (region-of w)) (w-lt (left-of reg)) (w-bm (bottom-of reg)) (w-ht (height-of reg)) (w-wid (width-of reg))) (setf (window-of vp) w) (setf (bounds-of vp) (list xmin xmax ymin ymax)) (when (contains-p (make-region) vp) ;; transform bounds to window coords (setf (bounds-of vp) (list (+ w-lt (* xmin w-wid)) (+ w-lt (* xmax w-wid)) (+ w-bm (* ymin w-ht)) (+ w-bm (* ymax w-ht))))) vp)) ;;;================================================================= ;;; conversion of types ;;;================================================================= (eval-when (:compile-toplevel :load-toplevel :execute) (proclaim '(inline wb-region wb-position view-region view-position))) (defun wb-region ( region) ;; returns coords of region as a wb:region (wb:make-region (left-of region ) (bottom-of region ) (1+ (width-of region )) (1+ (height-of region )))) (defun wb-position (p) ;; returns coords of p as a wb:position (wb:make-position (2d-position-x p) (2d-position-y p))) (defun view-region (wb-region) (make-region (wb:region-left wb-region) (wb:region-right wb-region) (wb:region-bottom wb-region) (wb:region-top wb-region))) (defun view-position (wb-position) (make-2d-position (wb:position-x wb-position) (wb:position-y wb-position))) (defmacro set-viewport-size (viewport size) "Sets smaller of viewport width and height to size" (let ((c (gensym)) (cz (gensym)) (s1 (gensym)) (s2 (gensym))) `(let* ((,c (centre-of ,viewport)) (,s1 (truncate ,size 2)) (,s2 (- ,size ,s1)) ,cz) (cond ((< (width-of ,viewport) (height-of ,viewport) ) (setq ,cz (2d-position-x ,c)) (setf (left-of ,viewport) (- ,cz ,s1)) (setf (right-of ,viewport) (+ ,cz ,s2))) (t (setq ,cz (2d-position-y ,c)) (setf (bottom-of ,viewport) (- ,cz ,s1)) (setf (top-of ,viewport) (+ ,cz ,s2))))))) (defmacro set-square-viewport-size (viewport size) (let ((c (gensym)) (cx (gensym)) (cy (gensym)) (s1 (gensym)) (s2 (gensym))) `(let* ((,c (centre-of ,viewport)) (,cx (2d-position-x ,c)) (,cy (2d-position-y ,c)) (,s1 (truncate ,size 2)) (,s2 (- ,size ,s1))) (setf (bounds-of ,viewport) (list (- ,cx ,s1) (+ ,cx ,s2) (- ,cy ,s1) (+ ,cy ,s2)))))) (defmacro set-square-viewport-center (viewport x y) (let ((size (gensym)) (s1 (gensym)) (s2 (gensym))) `(let* ((,size (width-of ,viewport)) (,s1 (truncate ,size 2)) (,s2 (- ,size ,s1))) (setf (bounds-of ,viewport) (list (- ,x ,s1) (+ ,x ,s2) (- ,y ,s1) (+ ,y ,s2)))))) #| (defmacro set-viewport-width-height (viewport w h) (let ((c (gensym)) (cx (gensym)) (cy (gensym)) (w1 (gensym)) (w2 (gensym)) (h1 (gensym)) (h2 (gensym))) `(let* ((,c (centre-of ,viewport)) (,cx (2d-position-x ,c)) (,cy (2d-position-y ,c)) (,w1 (truncate ,w 2)) (,w2 (- ,w ,w1)) (,h1 (truncate ,h 2)) (,h2 (- ,h ,h1))) (setf (bounds-of ,viewport) (list (- ,cx ,w1) (+ ,cx ,w2) (- ,cy ,h1) (+ ,cy ,h2)))))) |# (defmacro set-viewport-width-height (viewport w h) (let ((c (gensym)) (cx (gensym)) (cy (gensym)) (w1 (gensym)) (w2 (gensym)) (h1 (gensym)) (h2 (gensym))) `(let* ((,c (centre-of ,viewport)) ,cx ,cy ,w1 ,w2 ,h1 ,h2) (declare (ignorable ,c ,cx ,cy ,w1 ,w2 ,h1 ,h2)) (when ,w (setq ,cx (2d-position-x ,c)) (setq ,w1 (truncate ,w 2)) (setq ,w2 (- ,w ,w1)) (setf (left-of ,viewport) (- ,cx ,w1)) (setf (right-of ,viewport) (+ ,cx ,w2))) (when ,h (setq ,cy (2d-position-y ,c)) (setq ,h1 (if ,h (truncate ,h 2))) (setq ,h2 (if ,h (- ,h ,h1))) (setf (bottom-of ,viewport) (- ,cy ,h1)) (setf (top-of ,viewport) (+ ,cy ,h2)))))) (defmacro set-square-region-center (region x y) (let ((r (gensym)) ) `(let* ((,r (radius-of ,region))) (setf (bounds-of ,region) (list (- ,x ,r) (+ ,x ,r) (- ,y ,r) (+ ,y ,r)))))) (defun copy-region (r) (copy-seq r)) (eval-when (:compile-toplevel :load-toplevel :execute) (proclaim '(inline line-segment-intersectp))) (defun line-segment-intersectp(x1 y1 x2 y2 u1 v1 u2 v2) (let* ((dx (- x2 x1)) (dy (- y2 y1)) (du (- u2 u1)) (dv (- v2 v1)) (xu (- x1 u1)) (yv (- y1 v1)) (d (- (* du dy) (* dx dv)))) (and (not (zerop d)) (<= 0 (/ (- (* dy xu) (* dx yv)) d) 1) (<= 0 (/ (- (* dv xu) (* du yv)) d) 1))))
23,830
Common Lisp
.l
523
35.931166
117
0.520908
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
38bf98c97a3fe18e18082b1f3aa67edcb463fdc9fee53c6029992980d21688ab
33,186
[ -1 ]
33,187
linkbounds-macros-old.lsp
rwoldford_Quail/source/views/views-macros/linkbounds-macros-old.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; linkbounds-macros.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (defmacro with-tics=breaks (views axis &body do-form) (let ((v (gensym)) (d (gensym)) (i (gensym)) (hist-list (gensym))) `(let ((,hist-list (loop for ,v in ,views when (and (typep ,v 'histogram ) (eq ,axis (axis-of-orientation ,v))) collect (list ,v)))) (unless (null ,hist-list) (loop for ,v in ,views when (and (typep ,v 'axis ) (eq ,axis (axis-of-orientation ,v)) (setq ,i (position (tic-list-of ,v) ,hist-list :key #'(lambda(,d) (break-points-of (car ,d))) :test #'equal))) do (push ,v (cdr (elt ,hist-list ,i))))) ,@do-form (unless (null ,hist-list) (loop for ,d in ,hist-list do (mapcar #'(lambda(,v) (setf (tic-list-of ,v) (break-points-of (car ,d)))) (cdr ,d))))))) (defmacro with-linked-extent (view axis &body do-form) (let ((delta-regions (gensym)) (old-brs (gensym)) (views (gensym)) (v (gensym)) (br (gensym)) (d (gensym)) (vs (gensym)) (ds (gensym)) (mod-views (gensym)) (mod-deltas (gensym)) ) `(let* ((,views (if (listp ,view) ,view (if (eq ,axis :x) (link-bounds-x-of ,view) (if (eq ,axis :y) (link-bounds-y-of ,view))))) (,old-brs (mapcar #'bounding-region-of ,views)) (,delta-regions (compute-region-shifts ,views))) (with-tics=breaks ,views ,axis ,@do-form (loop for ,v in ,views for ,br in ,old-brs for ,d in ,delta-regions when (or (not (eq ,br (bounding-region-of ,v))) (and (typep ,v 'd-view) (has-variates-p ,v))) collect ,v into ,vs collect ,d into ,ds finally (setq ,mod-views ,vs ,mod-deltas ,ds))) (if (eq ,axis :x) (set-view-extents ,views :x (maximize-x-extents ,mod-views ,mod-deltas) ,delta-regions ) (if (eq ,axis :y) (set-view-extents ,views :y (maximize-y-extents ,mod-views ,mod-deltas) ,delta-regions ))) (loop for ,v in ,views when (and (typep ,v 'axis) (not (member ,v ,mod-views))) do (set-bounding-region ,v :region (bounding-region-of ,v) :pretty? nil :ignore-x? (eq ,axis :y) :ignore-y? (eq ,axis :x))) ))) (defmacro with-constrained-extent (view axis draw? &body do-form) (let ( (views (gensym)) (v (gensym))) `(let* ((,views (if (listp ,view) ,view (if (eq ,axis :x) (link-bounds-x-of ,view) (if (eq ,axis :y) (link-bounds-y-of ,view)))))) (when ,draw? (loop for ,v in ,views do (erase-view ,v))) (with-linked-extent ,view ,axis ,@do-form) (loop for ,v in ,views do (remap-to-viewports ,v :erase? nil :draw? ,draw?))))) (defmacro with-constrained-extents (view draw? &body do-form) (let ( (views (gensym)) (v (gensym)) ) `(let* ((,views (if (listp ,view) ,view (link-bounds-of ,view)))) (when ,draw? (loop for ,v in ,views do (erase-view ,v))) (with-linked-extent ,view :x (with-linked-extent ,view :y ,@do-form)) (loop for ,v in ,views do (remap-to-viewports ,v :erase? nil :draw? ,draw?)))))
4,818
Common Lisp
.l
109
29.577982
92
0.419756
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
2c0688ce66759bb225123094b31faa51de0a619e0b8275bb4ac4a8783b36c04a
33,187
[ -1 ]
33,188
linkbounds-macros.lsp
rwoldford_Quail/source/views/views-macros/linkbounds-macros.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; linkbounds-macros.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (defmacro with-tics=breaks (views axis &body do-form) (let ((i (gensym "i")) (hist-list (gensym "hist"))) `(let* ((,i ) (,hist-list (loop for v in ,views when (and (typep v 'histogram-view ) (eq ,axis (axis-of-orientation v))) collect (list v)))) (unless (null ,hist-list) (loop for v in ,views when (and (typep v 'axis ) (eq ,axis (axis-of-orientation v)) (setq ,i (position (tic-list-of v) ,hist-list :key #'(lambda(d) (break-points-of (car d))) :test #'equal))) do (push v (cdr (elt ,hist-list ,i))))) ,@do-form (unless (null ,hist-list) (loop for d in ,hist-list do (mapcar #'(lambda(v) (setf (tic-list-of v) (break-points-of (car d)))) (cdr d))))))) (defmacro with-linked-extent (view axis &body do-form) (let ( (old-brs (gensym "old-brs")) (views (gensym "views")) (v (gensym "v")) (br (gensym "br")) ;(d (gensym "d")) (vs (gensym "vs")) ;(ds (gensym "ds")) (mod-views (gensym "mod-views")) ) `(let* ((,mod-views) (,views (if (listp ,view) ,view (if (eq ,axis :x) (link-bounds-x-of ,view) (if (eq ,axis :y) (link-bounds-y-of ,view))))) (,old-brs (mapcar #'bounding-region-of ,views)) ) (with-tics=breaks ,views ,axis ,@do-form (loop for ,v in ,views for ,br in ,old-brs when (or (not (eq ,br (bounding-region-of ,v))) (and (typep ,v 'd-view) (has-variates-p ,v))) collect ,v into ,vs finally (setq ,mod-views ,vs))) (if (eq ,axis :x) (set-view-extents ,views :x :region (maximize-x-extents ,mod-views )) (if (eq ,axis :y) (set-view-extents ,views :y :region (maximize-y-extents ,mod-views )))) (loop for ,v in ,views when (and (typep ,v 'axis) (not (member ,v ,mod-views))) do (set-bounding-region ,v :region (bounding-region-of ,v) :pretty? nil :ignore-x? (eq ,axis :y) :ignore-y? (eq ,axis :x))) ))) (defmacro with-constrained-extent (view axis draw? &body do-form) (let ( (views (gensym))) `(let* ((,views (if (listp ,view) ,view (if (eq ,axis :x) (link-bounds-x-of ,view) (if (eq ,axis :y) (link-bounds-y-of ,view)))))) (when ,draw? (loop for v in ,views do (erase-view v))) (with-linked-extent ,view ,axis ,@do-form) (loop for v in ,views do (remap-to-viewports v :erase? nil :draw? ,draw?))))) (defmacro with-constrained-extents (view draw? &body do-form) (let ( (views (gensym)) (v (gensym)) ) `(let* ((,views (if (listp ,view) ,view (link-bounds-of ,view)))) (when ,draw? (loop for ,v in ,views do (erase-view ,v))) (with-linked-extent ,view :x (with-linked-extent ,view :y ,@do-form)) (loop for ,v in ,views do (remap-to-viewports ,v :erase? nil :draw? ,draw?)))))
4,605
Common Lisp
.l
106
29.009434
92
0.413975
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e43c7f89ef9d7e7a5ac378794f4c7179dea5a3a0d1de27e1d6edc8f6f1179475
33,188
[ -1 ]
33,189
clone.lsp
rwoldford_Quail/source/views/clone/clone.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; clone.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1993 George Washington University ;;; ;;; ;;; ;;;------------------------------------------------ (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(view-clone-list clone-view-fn clone-view-fn-prompt subview-keys-of))) (defgeneric view-clone-list (view) (:documentation "Returns an argument list to be passed to clones")) (defgeneric subview-clone-list (view) (:documentation "Returns an argument list to clone subviews")) (defgeneric toplevel-clone-list (view) (:documentation "Toplevel part of argument list for cloning")) (defgeneric subview-keys-of (view) (:documentation "Returns a list of keywords. ~ When constructing a view, if a keyword in this list~ appears more than once in the view construction arglist~ the values are appended.")) (defgeneric clone-view-fn (view &optional new-name) (:documentation "Returns an function which will construct a clone of view")) (defun clone-view-fn-prompt(view &key viewport) (let* ((pos (prompt-position view viewport)) (name (wb:prompt-user :result-type 'symbol :read-type :read :prompt-string "Name of function?" :left (2d-position-x pos) :top (2d-position-y pos)))) (clone-view-fn view name))) (defmethod clone-view-fn ((self view) &optional new-name ) (let* ((clone-list (view-clone-list self))) (if new-name (apply #'make-view-constructor-with-doc new-name (class-name (class-of self)) clone-list) (apply #'make-view-constructor-fn (class-name (class-of self)) clone-list)))) (defmethod view-clone-list ((self view)) (append (toplevel-clone-list self) (subview-clone-list self))) (defmethod toplevel-clone-list ((self view))) (defmethod subview-clone-list ((self view))) (defmethod toplevel-clone-list :around ((self view)) (append (list :type (class-name (class-of self))) (unless (linkable-bounds-x-p self) (list :linkable-bounds-x? nil)) (unless (linkable-bounds-y-p self) (list :linkable-bounds-y? nil)) (call-next-method) (loop for (a . b) in (drawing-style-of self) collect a collect b))) (defmethod subview-keys-of ((self view))) (defmethod subview-keys-of ((self one-per-case-mixin)) (list :case-view)) (defmethod subview-clone-list ((self one-per-case-mixin)) (let* ((sub (first (subviews-of self)))) (if sub (list :case-view (view-clone-list sub))))) (defmethod subview-clone-list ((self display-list)) (let* ((sub (first (subviews-of self)))) (if sub (list :item-type (view-clone-list sub))))) (defmethod toplevel-clone-list ((self orientation-mixin )) (append (list :orientation (orientation-of self)) (call-next-method))) (defmethod toplevel-clone-list ((self justification-mixin )) (append (list :justification (justification-of self)) (call-next-method))) (defmethod toplevel-clone-list ((self position-key-mixin)) (append (default-positions-of self) (call-next-method) )) (defmethod toplevel-clone-list ((self boxed-view-mixin)) (append (list :box? (box-p self)) (call-next-method) )) (defmethod toplevel-clone-list ((self boxed-subview-mixin)) (append (list :box-views? (box-views-p self)) (call-next-method) )) (defmethod toplevel-clone-list ((self display-list)) (append (list :display-list-border (display-list-border-of self)) (call-next-method) )) (defmethod subview-keys-of ((self boxplot-view)) (list :case-view :boxes)) (defmethod subview-clone-list ((self boxplot-view)) (let* ((subs (subviews-of self)) (box (first subs)) (point (fifth subs)) clone-args) (if box (setq clone-args (list :boxes (view-clone-list box)))) (if point (setq clone-args (append clone-args (list :case-view (view-clone-list point))))) clone-args)) (defmethod toplevel-clone-list ((self bar)) (append (list :orientation (orientation-of self) :collect-styles? (collect-styles-p self)) (call-next-method))) (defmethod toplevel-clone-list ((self function-view)) (append (list :function (function-of self) :nlines (nlines-of self) :domain (domain-of self)) (call-next-method))) (defmethod toplevel-clone-list ((self label )) (let ((tx (text-of self))) (if (functionp tx) (append (list :text (text-of self)) (call-next-method)) (call-next-method) ) )) (defmethod toplevel-clone-list ((self line)) (append (list :slope (slope-of self) :intercept (intercept-of self)) (call-next-method))) (defmethod toplevel-clone-list ((self fitted-line)) (append (list :fit-fn (fit-fn-of self)) (call-next-method)) ) (defmethod toplevel-clone-list ((self flip-mixin)) (append (list :flip-x? (flip-x-p self) :flip-y? (flip-y-p self)) (call-next-method))) (defmethod toplevel-clone-list ((self edge-lines-mixin)) (append (list :lines-to (lines-to self) ) (call-next-method))) (defmethod toplevel-clone-list ((self smooth-mixin)) (append (list :fit-fn (fit-fn-of self) :smooth-par (smooth-par-of self)) (call-next-method)) ) (defmethod toplevel-clone-list ((self moving-dview-mixin)) (append (list :coords-scale-method (coords-scale-method-of self) ) (call-next-method)) ) (defmethod toplevel-clone-list ((self rotating-cloud)) (append (list :draw-axis? (draw-axis-p self) :draw-label? (draw-label-p self) ) (call-next-method)) ) (defmethod toplevel-clone-list ((self histogram-view)) (append (list :histogram-scale (histogram-scale-of self) ) (call-next-method)) ) (defmethod toplevel-clone-list ((self axis)) (append (list :ntics (ntics-of self) :internal-tics? (internal-tics-p self)) (call-next-method))) (defmethod toplevel-clone-list ((self point-symbol)) (append (list :label (label-of self) ) (call-next-method))) (defmethod toplevel-clone-list ((self view-with-size)) (append (list :size (view-size-of self) ) (call-next-method))) (defmethod toplevel-clone-list ((self plot)) (let ((iv (interior-view-of self)) (ans (call-next-method))) (when iv (if (compute-applicable-methods #'link-bounds-x-p (list iv )) (setq ans (append (list :link-bounds-x? (link-bounds-x-p iv)) ans ))) (if (compute-applicable-methods #'link-bounds-y-p (list iv )) (setq ans (append (list :link-bounds-y? (link-bounds-y-p iv)) ans )))) ans)) (defmethod subview-keys-of ((self histogram-view)) (list :bars)) (defmethod subview-clone-list ((self histogram-view)) (let ((bar (first (subviews-of self)))) (if bar (list :bars (view-clone-list bar)) ))) (defmethod subview-keys-of ((self plot)) (list :title :left-view :right-view :bottom-view :top-view :left-label :right-label :bottom-label :top-label :interior-view)) (defmethod subview-clone-list ((self plot)) (flet ((get-clone-list(v) (if v (view-clone-list v)))) (let ((iv (interior-views-of self)) (ti (title-of self)) (lv (left-views-of self)) (rv (right-views-of self)) (bv (bottom-views-of self)) (tv (top-views-of self)) (ll (left-label-of self)) (rl (right-label-of self)) (bl (bottom-label-of self)) (tl (top-label-of self))) (loop for sub in (list ti iv lv rv bv tv ll rl bl tl) for key in (list :title :interior-view :left-view :right-view :bottom-view :top-view :left-label :right-label :bottom-label :top-label ) nconc (list key (if (listp sub) (mapcar #'get-clone-list sub) (get-clone-list sub))))))) (defmethod subview-clone-list ((self grid-plot)) (flet ((get-clone-list(v) (if v (view-clone-list v))) (non-null-elt(v) (find t v :key #'(lambda(x) (not (null x)))))) (append (let ((iv (interior-views-of self)) (ti (title-of self)) (lv (non-null-elt (left-views-of self))) (rv (non-null-elt (right-views-of self))) (bv (non-null-elt (bottom-views-of self))) (tv (non-null-elt (top-views-of self))) (ll (left-label-of self)) (rl (right-label-of self)) (bl (bottom-label-of self)) (tl (top-label-of self))) (loop for sub in (list ti iv lv rv bv tv ll rl bl tl) for key in (list :title :interior-view :left-view :right-view :bottom-view :top-view :left-label :right-label :bottom-label :top-label ) nconc (list key (if (listp sub) (mapcar #'get-clone-list sub) (get-clone-list sub)))))))) (defmethod subview-keys-of ((self view-layout)) '(:subviews)) (defmethod subview-clone-list ((self view-layout)) (flet ((get-clone-list(v) (if v (view-clone-list v)))) `(:subviews ,(loop for sub in (layout-views-of self) collect (mapcar #'get-clone-list sub))))) (defmethod toplevel-clone-list ((self view-layout)) (append `( :positions ,(positions-of self) :link-bounds-x? ,(link-bounds-x-p self) :link-bounds-y? ,(link-bounds-y-p self)) (call-next-method))) (defmethod toplevel-clone-list ((self table-layout)) (append `( :scaled-dimension ,(scaled-dimension-of self) :justification ,(justification-of self) ) (call-next-method))) (defmethod subview-clone-list ((self grid-layout)) (flet ((get-clone-list(v) (if v (view-clone-list v)))) `(:subviews ,(loop for sub in (layout-views-of self) collect (mapcar #'get-clone-list sub)) ))) (defmethod subview-clone-list ((self batch-layout)) (flet ((get-clone-list(v) (if v (view-clone-list v)))) `(:subviews ,(mapcar #'get-clone-list (car (layout-views-of self)))))) (defmethod subview-clone-list ((self 1d-layout)) (flet ((get-clone-list(v) (if v (view-clone-list v)))) `(:subviews ,(mapcar #'get-clone-list (car (layout-views-of self)))))) (defmethod toplevel-clone-list ((self grid-layout)) (call-next-method)) (defmethod subview-keys-of ((self pairs-layout)) (list :diag-view :pairs-view)) (defmethod subview-clone-list ((self pairs-layout)) (flet ((get-clone-list(v) (if v (view-clone-list v)))) (let ((pair (second (layout-views-of self))) (diag (first (layout-views-of self)))) `(:pairs-view ,(mapcar #'get-clone-list pair) :diag-view ,(mapcar #'get-clone-list diag))))) (defmethod subview-clone-list ((self view-layers)) (flet ((get-clone-list(v) (if v (view-clone-list v)))) `(:subviews ,(loop for sub in (subviews-of self) collect (get-clone-list sub)) :link-bounds-x? ,(link-bounds-x-p self) :link-bounds-y? ,(link-bounds-y-p self))))
12,216
Common Lisp
.l
290
33.903448
95
0.593997
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f4ac7c103d0aab23fb3b490b303ce9a7d2be323fd94a23e22681bbf68f01c15c
33,189
[ -1 ]
33,190
copy.lsp
rwoldford_Quail/source/views/clone/copy.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; copy.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(copy-view copy-view-fn *link-on-copy?* view-copy-list))) (defgeneric view-copy-list (view) (:documentation "Returns an argument list to be passed to copies")) (defmethod view-copy-list ((self view)) (append (toplevel-copy-list self) (subview-copy-list self))) (defmethod toplevel-copy-list ((self view)) (toplevel-clone-list self)) (defmethod subview-copy-list ((self view)) ) (defmethod toplevel-copy-list :around ((self view)) (append (required-data-args-of self) (call-next-method))) (defmethod subview-copy-list ((self compound-view)) (subview-clone-list self)) (defmethod toplevel-copy-list ((self one-per-case-mixin)) (append (list :case-views-from self :ordered-case-views? t) (call-next-method))) (defmethod toplevel-copy-list ((self pairs-layout)) (append (list :cloud-subviews-from (car (subviews-of-type self 'one-per-case-mixin)) :ordered-case-views? t) (call-next-method))) (defmethod toplevel-copy-list ((self d-view )) (append (list :dataset (dataset-of self) :cases (cases-of self) :coords (coords-cache-of self) :variates (variates-of self) :value-fn (value-fn-of self)) (call-next-method))) (defmethod toplevel-copy-list ((self axis)) (append (call-next-method) (multiple-value-bind (min max) (extent-of self) (list :tic-list (slot-value self 'tic-list) :min min :max max :pretty? nil )))) (defmethod toplevel-copy-list ((self histogram-view)) (append (call-next-method) (list :break-points (break-points-of self)))) (defmethod toplevel-copy-list ((self label )) (append (list :text (text-of self)) (call-next-method))) (defmethod toplevel-copy-list ((self rotating-cloud )) (append (list :x-text (x-text-of self) :y-text (y-text-of self) :z-text (z-text-of self)) (call-next-method))) (defmethod required-data-args-of ((self 1d-view)) (list :var (variate-of self) :function (func-of self) :transform (transform-of self))) (defmethod required-data-args-of ((self 2d-view)) (list :x (x-variate-of self) :y (y-variate-of self) :x-function (x-func-of self) :y-function (y-func-of self) :x-transform (x-transform-of self) :y-transform (y-transform-of self))) (defmethod required-data-args-of ((self 3d-view)) (list :x (x-variate-of self) :y (y-variate-of self) :z (z-variate-of self) :x-function (x-func-of self) :y-function (y-func-of self) :z-function (z-func-of self) :x-transform (x-transform-of self) :y-transform (y-transform-of self) :z-transform (z-transform-of self))) (defmethod required-data-args-of ((self d-view)) (list :vars (vars-of self) :functions (functions-of self) :transforms (transforms-of self))) (defmethod required-data-args-of ((self view)) ) (defmethod required-data-args-of :around ((self view)) (let ((r (call-next-method))) (setf (getf r :data) (viewed-object-of self)) r)) (defmethod toplevel-copy-list ((self plot)) (append (call-next-method) (list :initform-fn nil))) (defmethod toplevel-copy-list ((self view-layout)) (append `( :bounding-region ,(copy-region (bounding-region-of self)) :subview-locns ,(sub-view-locns-of self) ) (call-next-method))) (defmethod toplevel-copy-list ((self table-layout)) (append `( :scales ,(scales-of self) ) (call-next-method))) (defmethod required-data-args-of ((self pairs-layout)) (loop for row in (row-format self) for (vi fi tri) = (loop for (v) in row thereis (and (typep v '2d-view) (list (y-variate-of v) (y-func-of v)(y-transform-of v)))) collect vi into v collect fi into f collect tri into tr finally (return (list :vars v :functions f :transforms tr)))) (defmethod required-data-args-of ((self batch-layout)) (list :batches nil)) (defmethod required-data-args-of ((self batch-display-list)) (list :batches (batches-of self) :by-vars (by-vars-of self)) ) (defmethod toplevel-copy-list ((self 1d-layout)) (append (call-next-method) (list :subview-constructor #'default-layout-sub-views))) (defmethod toplevel-copy-list ((self xy-layout)) (append (call-next-method) (list :subview-constructor #'default-layout-sub-views))) (defmethod toplevel-copy-list ((self grid-layout)) (append `(:nrows ,(nrows-of self) :ncols ,(ncols-of self) ) (call-next-method))) (defmethod required-data-args-of ((self 1d-layout)) (list :vars nil )) (defmethod required-data-args-of ((self xy-layout)) (list :x-vars nil :y-vars nil )) (defmethod subview-copy-list ((self view-layout)) (flet ((get-copy-list(v) (if v (view-copy-list v)))) `(:subviews ,(loop for sub in (layout-views-of self) collect (mapcar #'get-copy-list sub)) ))) (defmethod subview-copy-list ((self plot)) (flet ((get-copy-list(v) (if v (view-copy-list v)))) (let ((iv (interior-views-of self)) (ti (title-of self)) (lv (left-views-of self)) (rv (right-views-of self)) (bv (bottom-views-of self)) (tv (top-views-of self)) (ll (left-labels-of self)) (rl (right-labels-of self)) (bl (bottom-labels-of self)) (tl (top-labels-of self))) (loop for sub in (list ti iv lv rv bv tv ll rl bl tl) for key in (list :title :interior-view :left-view :right-view :bottom-view :top-view :left-label :right-label :bottom-label :top-label ) nconc (list key (if (listp sub) (mapcar #'get-copy-list sub) (get-copy-list sub))))))) (defmethod subview-copy-list ((self grid-plot)) (flet ((get-copy-list(v) (cond ((and v (listp v)) (loop for vi in v when vi collect (view-copy-list vi))) (t (if v (view-copy-list v)))))) (let ((iv (interior-views-of self)) (ti (title-of self)) (lv (left-views-of self)) (rv (right-views-of self)) (bv (bottom-views-of self)) (tv (top-views-of self)) (ll (left-labels-of self)) (rl (right-labels-of self)) (bl (bottom-labels-of self)) (tl (top-labels-of self))) (loop for sub in (list ti iv lv rv bv tv ll rl bl tl) for key in (list :title :interior-view :left-view :right-view :bottom-view :top-view :left-label :right-label :bottom-label :top-label ) nconc (list key (if (listp sub) (mapcar #'get-copy-list sub) (get-copy-list sub))))))) (defun copy-view-fn (view &key (draw? nil supplied-p)) (apply #'make-view-constructor-fn (class-name (class-of view)) (if supplied-p (append (list :draw? draw?) (view-copy-list view)) (view-copy-list view)))) (defun copy-view (view &key (draw? nil) viewport) (setq viewport (or viewport (car (viewports-of view)))) (let ((new-instance (funcall (copy-view-fn view :draw? nil)))) (if draw? (if viewport (let* ((l 10) (b 10) (w (make-view-window :title (view-window-title new-instance) :region (make-region l (+ l (width-of viewport) 15) b (+ b (height-of viewport) 15))))) (draw-view new-instance :viewport (make-viewport w))) (draw-view new-instance))) new-instance))
8,902
Common Lisp
.l
217
32.299539
122
0.564274
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
7cd735329f58eedf5142723d2e56ad3d97c4e8b401f2644e07c7782c98ac443b
33,190
[ -1 ]
33,191
combine-args.lsp
rwoldford_Quail/source/views/clone/combine-args.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; combine-args.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1994 ;;; ;;; ;;; ;;;------------------------------------------------ (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( combine-subview-args))) (defgeneric combine-subview-args(view &rest args) (:documentation "If any of the keys in subview-keys appear more than once in args~ all values for that key are combined into a list")) (defun csa-arg-p(arg) (and (not (eq t arg)) (or (symbolp arg) (functionp arg) ;;(not (listp arg)) (keyword-list-p arg)) :single)) (defun layer-arg-p(arg) (and (listp arg) (every #'csa-arg-p arg) :layer)) (defun csa-add-args(a b) (cond ((and (listp a) (listp b)) (loop for key in a by #'cddr for val in (cdr a) by #'cddr do (setf (getf b key) val)) b) ((and (listp b) (symbolp a)) (setf (getf b :type) a) b) ((and (listp a) (symbolp b)) (unless (member :type a) (setf (getf a :type) b)) a) (t a))) (defun delete-extra-keyword-args(args) (loop with key-list = nil with k = 0 while (< k (length args)) for key = (elt args k) do (if (member key key-list) (setf args (concatenate 'list (subseq args 0 k) (subseq args (+ k 2)))) (progn (push key key-list) (incf k 2)))) args) (defmethod combine-subview-args ((self view) &rest args) (loop for key in (subview-keys-of self) for new-key-arg = (loop with other-vals for arg-val in (cdr args) by #'cddr for arg-key in args by #'cddr when (eq arg-key key) do (cond ((csa-arg-p arg-val) (setq other-vals (csa-add-args other-vals arg-val ))) (t nil)) finally (return other-vals)) when new-key-arg do (setf (second (member key args)) new-key-arg)) (delete-extra-keyword-args args) ) (defmethod combine-subview-args ((self plot) &rest args) (loop for key in (subview-keys-of self) for new-key-arg = (loop with other-vals with basic-type for arg-val in (cdr args) by #'cddr for arg-key in args by #'cddr when (eq arg-key key) do (cond ((csa-arg-p arg-val) (setq other-vals (cond ((eq basic-type :single) (csa-add-args other-vals arg-val )) ((eq basic-type :layer) (loop for o in other-vals collect (csa-add-args o arg-val) )) (t (setq basic-type :single) arg-val)))) ((layer-arg-p arg-val) (setq other-vals (cond ((eq basic-type :single) other-vals) ((eq basic-type :layer) (if (= (length other-vals) (length arg-val)) (loop for o in other-vals for a in arg-val collect (csa-add-args o a)) other-vals)) (t (setq basic-type :layer) arg-val)))) (t nil)) finally (return other-vals)) when new-key-arg do (setf (second (member key args)) new-key-arg)) (delete-extra-keyword-args args) ) (defmethod combine-subview-args ((self view-layout) &rest args) (loop for key in (subview-keys-of self) for new-key-arg = (loop with other-vals with basic-type for arg-val in (cdr args) by #'cddr for arg-key in args by #'cddr when (eq arg-key key) do (cond ((csa-arg-p arg-val) (setq other-vals (cond ((eq basic-type :single) (csa-add-args other-vals arg-val )) ((eq basic-type :list) (loop for o in other-vals collect (csa-add-args o arg-val) )) ((and basic-type (listp basic-type)) (loop for other in other-vals for b in basic-type when b collect (cond ((eq b :single) (csa-add-args other arg-val)) ((eq b :layer) (loop for o in other collect (csa-add-args o arg-val))) (t nil)))) (t (setq basic-type :single) arg-val)))) ((layer-arg-p arg-val) (setq other-vals (cond ((eq basic-type :single) other-vals) ((eq basic-type :list) (if (= (length other-vals) (length arg-val)) (loop for o in other-vals for a in arg-val collect (csa-add-args o a) ) other-vals)) ((and basic-type (listp basic-type)) (loop for other in other-vals for b in basic-type when b collect (cond ((eq b :single) b) ((= (length other) (length arg-val)) (loop for o in other for a in arg-val collect (csa-add-args o a) )) (t other)))) (t (setq basic-type :list) arg-val)))) ((and basic-type (listp basic-type)) (setq other-vals (loop for b in basic-type for a in arg-val for o in other-vals when b collect (cond ((and (eq b :single) (csa-arg-p a )) (csa-add-args o a)) ((and (eq b :layer) (layer-arg-p a)) (if (= (length o) (length a)) (loop for oi in o for ai in a collect (csa-add-args oi ai)) o)) (t o))))) (basic-type nil) ((setq basic-type (loop for a in arg-val collect (or (csa-arg-p a ) (layer-arg-p a)))) (setq other-vals arg-val)) (t nil)) finally (return other-vals)) when new-key-arg do (setf (second (member key args)) new-key-arg)) (delete-extra-keyword-args args) )
8,403
Common Lisp
.l
190
24.489474
92
0.386541
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f11c06a9d7c6d4b2acb09d4002f8ed182bba1c6e8c31c253515b9657df7eb058
33,191
[ -1 ]
33,192
function-info.lsp
rwoldford_Quail/source/views/utilities/function-info.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; function-info.lisp ;;; ;;; Catherine Hurley 1994 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(get-function))) (defun function-string (f &optional (default "??")) (cond ((symbolp f) (string f)) ((and (functionp f) (qk::function-name f)) (string (qk::function-name f))) ((functionp f) default) (t nil))) (defgeneric get-function(f) (:documentation "Returns a function for f.")) (defun get-quail-function(f) (loop for pkg in (list "QUAIL" "QUAIL-KERNEL") when (and (find-package pkg) (find-symbol (string f) pkg)) do (return (symbol-function (find-symbol (string f) pkg))))) (defmethod get-function (f) (cond ((null f) #'identity) ((symbolp f) (if (fboundp f) (symbol-function f) (or (get-quail-function f) (loop for f1 in (find-all-symbols f) when (fboundp f1) do (return (symbol-function f1)))))) ((functionp f) f) ((and (listp f) (eq (car f) 'lambda)) (eval `(function ,f))) ((and (listp f) (eq (car f) 'function)) (eval f)) (t #'identity))) (defmethod get-function ((f (eql 'median))) (if (fboundp 'median) (symbol-function 'median) (setf (symbol-function 'median) (get-quail-function 'median)))) (defmethod get-function ((f (eql 'mean))) (if (fboundp 'mean) (symbol-function 'mean) (setf (symbol-function 'mean) (get-quail-function 'mean)))) (defmethod get-function ((f (eql 'var))) (if (fboundp 'var) (symbol-function 'var) (setf (symbol-function 'var) (get-quail-function 'var)))) (defmethod get-function ((f (eql 'iqr))) (if (fboundp 'iqr) (symbol-function 'iqr) (setf (symbol-function 'iqr) (get-quail-function 'iqr)))) (defmethod get-function ((f (eql 'sd))) (if (fboundp 'sd) (symbol-function 'sd) (setf (symbol-function 'sd) (get-quail-function 'sd))))
2,510
Common Lisp
.l
66
28.5
86
0.479634
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3f93e390a574e257a0771700d1cc392ca9d1098d945801f032270fd3158cad38
33,192
[ -1 ]
33,193
class-info.lsp
rwoldford_Quail/source/views/utilities/class-info.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; class-info.lisp ;;; ;;; Catherine Hurley 1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(view-classes-with-spec list-view-classes))) (defun list-view-classes (&optional (class-name 'view-mixin)) "Returns a list of all view classes with class-name on~ the class precedence list.~ class-name defaults to 'view-mixin." (let ((base-class (find-class class-name nil )) class-names a-class) (if base-class (do-symbols (sym (find-package 'views) ) (unless (eq sym class-name) (setq a-class (find-class sym nil)) (if (and a-class (member base-class (qk:class-precedence-list a-class) )) (setq class-names (push sym class-names)))))) class-names)) (defun view-classes-with-spec(class-spec) (let ((view-classes (list-view-classes 'view))) (labels ((subclass (a b) (if (symbolp a) (setq a (find-class a))) (if (symbolp b) (setq b (find-class b))) (cond ((eq a b) nil) ((and (listp b) (eq 'not (car b))) (not (subclass a (second b)))) (t (member b (qk:class-precedence-list a) )))) (view-classes-not-spec(spec) (if (symbolp spec) (setq spec (find-class spec nil))) (if spec (loop for class in view-classes unless (subtypep class spec) collect class)))) (cond ((and class-spec (listp class-spec) (eq 'not (car class-spec))) (view-classes-not-spec (second class-spec))) ((and class-spec (listp class-spec) ) (let* ((class-op (case (car class-spec) (or #'some) (and #'every) (t nil))) (spec-classes (cdr class-spec))) (when class-op (loop for v in view-classes when (funcall class-op #'(lambda(x) (subclass v x)) spec-classes) collect v)))) ((symbolp class-spec) (list-view-classes class-spec)) (t nil)))) )
2,702
Common Lisp
.l
63
28.809524
109
0.436224
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5a3d968556cb570f1a6ebbd3cccbc98ae9c2e1fd5d85cfaa5275b75e07a82206
33,193
[ -1 ]
33,195
title-menu.lsp
rwoldford_Quail/source/views/utilities/title-menu.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; menus.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( make-plot-menu view-menu-list select-view-menu-list ))) (defun make-plot-menu () (let ((menu-items '( ("Scatterplot" (scatterplot)) ("Histogram" (histogram)) ("Boxplot" (boxplot)) ("ScatMatrix" (scat-mat)) ("3DPlot" (rotating-plot)) ("LinesPlot" (lines-plot)) ))) (wb:make-menu :items menu-items :title "Plot" :menu-type :title ) (wb:menu (wb:make-menu :items menu-items :title "Plot" :menu-type :title ) ))) (defun view-menu-list (view-symbol &optional fn) "Returns a menu item list of view classes inheriting from~ class named by view-symbol" (if fn (loop for class-name in (view-classes-with-spec view-symbol) collect `(,(format nil "~@(~A~)" class-name) (,fn ,class-name))) (loop for class-name in (view-classes-with-spec view-symbol) collect `(,(format nil "~@(~A~)" class-name) ,class-name)))) (defgeneric select-view-menu-list(view-symbol) (:documentation "Returns a menu item list of SOME view classes inheriting from~ class named by view-symbol")) (defmethod select-view-menu-list(view-symbol) (view-menu-list view-symbol)) #| (eval-when (eval load) (make-plot-menu)) |#
2,348
Common Lisp
.l
59
29.932203
123
0.465231
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fc40d2c1fbc733ff9bb03326a1f5c3ad368a93e2871e38436440ef558fe5a045
33,195
[ -1 ]
33,196
class-info2.lsp
rwoldford_Quail/source/views/utilities/class-info2.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; class-info.lisp ;;; ;;; Catherine Hurley 1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(view-classes-with-spec list-view-classes))) (defun class-precedence-list(class-name) (let ((class (find-class class-name nil))) (if class (mapcar #'class-name (qk:class-precedence-list class))))) (defun list-view-classes (&optional (class-name 'view-mixin)) "Returns a list of all view classes with class-name on the class precedence list.~ class-name defaults to 'view-mixin." (let ((base-class (find-class class-name nil )) class-names a-class) (if base-class (do-symbols (sym ( find-package 'views) ) (unless (eq sym class-name) (setq a-class (find-class sym nil)) (if (and a-class (member base-class (qk:class-precedence-list a-class))) (setq class-names (push sym class-names)))))) class-names)) (defun view-classes-with-spec (class-spec) (if (and class-spec (listp class-spec)) (let* ((spec-classes (cdr class-spec)) (spec-op (car class-spec)) (base-class-objs (mapcar #'find-class spec-classes)) class-names a-class-obj) (flet ((test (b) (if (eq spec-op 'and) (subsetp base-class-objs b) (intersection base-class-objs b)))) (do-symbols (sym (find-package 'views) ) (unless (member sym spec-classes) (setq a-class-obj (find-class sym nil)) (if (and a-class-obj (test (qk:class-precedence-list a-class-obj)) ;;(test (slot-value a-class-obj 'ccl::precedence-list)) ) (setq class-names (push sym class-names))))) class-names)) (list-view-classes class-spec)))
2,216
Common Lisp
.l
49
34.469388
109
0.505671
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
2ba826ea7e8d9343ddf7d7768bc3a20b1d63d0f3c6625b5b5427bee2768ccbb3
33,196
[ -1 ]
33,197
affinetrans.lsp
rwoldford_Quail/source/views/utilities/affinetrans.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; affinetrans.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(affine transform 2d-affine 3d-affine make-affine-transform affine-trans-p dimension-of matrix-of ;;(setf dimension-of ) (setf matrix-of ) apply-transform apply-transform! compose-transforms error-mismatched-dimensions premultiply-transform! rotate-transform! set-to-identity scale-transform! translate-transform! invert-transform *identity-2d-transform*))) ;;;---------------------------------------------------------------------------------- (defclass affine-transform () ((dimension :initarg :dimension :accessor dimension-of :documentation " the true dimension of the transform, (n *n)") (affine :initarg :affine :accessor matrix-of :documentation "an (n+1) *(n+1) array of reals, first n rows and columns ~ represent the transformation, the last column represents ~ the location shift") ) (:documentation "Affine transformations for viewing 2 and 3 dimensional objects.~ See Foley and Van Dam for reference. Note the transforms here operate ~ on columns whereas those in F+VD operate on row vectors" )) (defgeneric apply-transform (affine-transform item) (:documentation "applies the AFFINE TRANSFORM to ITEM ( list) ~ returning the resulting ITEM (list) ~ If self is a 2d-affine, item may be a 2d-position or a region")) (defgeneric apply-transform! (affine-transform item) (:documentation "applies the affine-transform self to item, placing results in item arguments ")) (defgeneric compose-transforms (affine-transform1 affine-transform2) (:documentation " composes affine-transform1 with affine-transform2 ~ returning the resulting AFFINE-TRANSFORM")) (defgeneric error-mismatched-dimensions (affine-transform1 affine-transform2) (:documentation "returns non-nil when the arguments have equal dimension")) (defgeneric premultiply-transform! (affine-transform multiplier) (:documentation " premultiply AFFINE-TRANSFORM by another AFFINE-TRANSFORM, ~ MULTIPLIER, storing result in AT")) (defgeneric rotate-transform! (affine-transform angle &optional (radians? nil)) (:documentation "rotates AFFINE-TRANSFORM SELF by ANGLE")) (defgeneric set-to-identity (affine-transform) (:documentation " AFFINE-TRANSFORM becomes the identity")) (defgeneric scale-transform! (affine-transform (scale number) &optional &rest other-scales) (:documentation " scales AFFINE-TRANSFORM by SCALE in the x-direction ~ and by OTHER-SCALES in the remaining directions. ~ If OTHER-SCALES is not present, ~ SCALE is applied in all to directions.")) (defgeneric translate-transform! (affine-transform (delta number) &optional &rest other-deltas) (:documentation " scales AFFINE-TRANSFORM by DELTA in the x-direction ~ and by OTHER-OTHER-DELTAS in the remaining directions. ~ If OTHER-DELTAS is not present, ~ SCALE is applied in all to directions.")) (defgeneric invert-transform (affine-transform) (:documentation " inverts the affine-transform")) (defgeneric make-affine-transform (dimension) (:documentation " returns an affine-transform with dimension dimension")) ;;;---------------------------------------------------------------------------------- (defun affine-trans-p (affine) (typep affine 'affine-transform)) (defclass 2d-affine (affine-transform) ((affine :documentation "A 3 by 3 array of reals, first 2 rows and colums represent ~ the transformation, the last column represents the location shift") (x-function :accessor x-function :documentation "function applied to object to retrieve its x location") (y-function :accessor y-function :documentation "function applied to object to retrieve its y location") (dimension :initform 2 :documentation " the true dimension of the transform, 2 by 2"))) (defclass 3d-affine (affine-transform) ((affine :documentation "A 4 by 4 array of reals, first 3 rows and columns ~ represent the transformation, the last column represents ~ the location shift.") (x-function :accessor x-function :documentation "Function applied to object to retrieve its x location") (y-function :accessor y-function :documentation "Function applied to object to retrieve its y location") (z-function :accessor z-function :documentation "Function applied to object to retrieve its z location") (dimension :initform 3 :documentation " the true dimension of the transform, 3 by 3"))) (defmethod apply-transform ((self 2d-affine) item) ;;; applies the TRANSFORM 2D-AFFINE to ITEM , returning the resulting ;;; 2d-POSITION /REGION/LIST (if (region-p item) (let ((top-right (apply-transform self (top-right-of item))) (bottom-left (apply-transform self (bottom-left-of item)))) (make-region (2d-position-x bottom-left) (2d-position-x top-right) (2d-position-y bottom-left) (2d-position-y top-right))) ;;else (multiple-value-bind (x y) (if (2d-position-p item) (values (2d-position-x item) (2d-position-y item)) (if (listp item) (values (first item) (second item)) (values (funcall (x-function self) item) (funcall (y-function self) item)))) (let ((mat (matrix-of self)) new-x new-y) (setq new-x (+ (* x (aref mat 0 0)) (* y (aref mat 0 1)) (aref mat 0 2))) (setq new-y (+ (* x (aref mat 1 0)) (* y (aref mat 1 1)) (aref mat 1 2))) (if (listp item) (list new-x new-y) (make-2d-position new-x new-y)))))) (defmethod apply-transform! ((at 2d-affine) item) ;;; applies the 2D-AFFINE to ITEM, placing results in ITEM arguments (let ((top-right (apply-transform at (top-right-of item))) (bottom-left (apply-transform at (bottom-left-of item)))) (setf (bounds-of item) (list (2d-position-x bottom-left) (2d-position-x top-right) (2d-position-y bottom-left) (2d-position-y top-right))) item)) (defmethod compose-transforms ((at1 affine-transform) (at2 affine-transform)) ;;; composes AFFINE-TRANSFORMs AT1 with AT2 , returning the resulting ;;; AFFINE-TRANSFORM (if (not (eql (dimension-of at1) (dimension-of at2))) (error-mismatched-dimensions at1 at2) ;; else (let* ((size (dimension-of at1)) (result (make-affine-transform size)) (mat1 (matrix-of at1)) (mat2 (matrix-of at2)) (mat3 (matrix-of result )) ) ; (loop for i from 0 to size do (do ((i 0 (incf i))) ((> i size)) ; (loop for j from 0 to size do (do ((j 0 (incf j))) ((> j size)) (setf (aref mat3 i j) ; (loop for k from 0 to size sum (do ((sum-mat1 0) (k 0 (incf k))) ((> k size) sum-mat1) (incf sum-mat1 (* (aref mat1 i k) (aref mat2 k j))))))) result))) (defmethod error-mismatched-dimensions ((at1 affine-transform) (at2 affine-transform)) (quail-error "The transforms ~S and ~S do not have matching dimensions" at1 at2)) (defmethod premultiply-transform! ((at affine-transform) (multiplier affine-transform)) ;;; premultiply AFFINE-TRANSFORM AT by another AFFINE-TRANSFORM, MULTIPLIER, ;;; storing result in AT (if (not (eql (dimension-of at) (dimension-of multiplier))) (error-mismatched-dimensions at multiplier) ;; else (let* ((size (1+ (dimension-of at))) (mat1 (matrix-of multiplier)) (mat2 (matrix-of at) ) (mat3 (make-array (list size size) :initial-element 0.0))) (dotimes (i size) (dotimes (j size) (dotimes (k size) (incf (aref mat3 i j) (* (aref mat1 i k) (aref mat2 k j)))))) (setf (matrix-of at) mat3))) at) (defmethod rotate-transform! ((self affine-transform) (angle number) &optional (radians? nil)) ;; rotates the AFFINE-TRANSFORM SELF by ANGLE (quail-cerror "Method has been implemented " "This method does nothing-please implement")) (defmethod rotate-transform! ((self 2d-affine) (angle number) &optional (radians? nil)) ;; rotates the 2D-AFFINE SELF by ANGLE (unless radians? (setq angle (/ angle 180.0))) (let* ((c (cos angle)) (s (sin angle)) (mat (matrix-of self)) (a00 (aref mat 0 0)) (a01 (aref mat 0 1)) (a10 (aref mat 1 0)) (a11 (aref mat 1 1))) (setf (aref mat 0 0) (- (* c a00) (* s a10))) (setf (aref mat 0 1) (- (* c a01) (* s a11))) (setf (aref mat 1 0) (+ (* c a00) (* s a10))) (setf (aref mat 1 1) (+ (* c a01) (* s a11))))) (defmethod set-to-identity ((self affine-transform)) ;; the AFFINE-TRANSFORM SELF becomes the identity (let* ((matrix (matrix-of self)) (dim (array-dimension matrix 0))) (dotimes (i dim) (dotimes (j dim) (setf (aref matrix i j) 0.0)) (setf (aref matrix i i) 1.0)))) (defmethod scale-transform! ((self affine-transform) (scale number) &optional &rest other-scales) ;; scales the AFFINE-TRANSFORM SELF by SCALES in the x-direction and by ;; OTHER-SCALES in the remaining directions. If OTHER-SCALES is not ;; present,SCALE is applied in all to directions (let ((scale-list (if other-scales (cons scale other-scales) (make-list (dimension-of self) :initial-element scale))) (mat (matrix-of self))) (loop for scale-amt in scale-list for i upfrom 0 do ; (loop for j from 0 to (dimension-of self) do (let ((dos (dimension-of self)) (do ((j 0 (incf j))) ((> j dos)) (setf (aref mat i j) (* (aref mat i j) scale-amt))))))) (defmethod translate-transform! ((self affine-transform) (delta number) &optional &rest other-deltas) ;; translates the AFFINE-TRANSFORM SELF by DELTA in the x-direction ;; and by OTHER-DELTAS in the other directions. If OTHER-DELTAS are ;; not present,DELTA is applied to all directions (loop with dim = (dimension-of self) with mat = (matrix-of self) with delta-list = (if other-deltas (cons delta other-deltas) (make-list dim :initial-element delta)) for delta-amt in delta-list for i upfrom 0 do (incf (aref mat i dim) delta-amt))) (defmethod invert-transform ((at 2d-affine ) ;; inverts the transform at (let* ((size (dimension-of at)) (new-at (make-affine-transform size)) (mat (matrix-of at)) (new-mat (matrix-of new-at)) (d (- (* (aref mat 0 0 ) (aref mat 1 1 )) (* (aref mat 0 1 ) (aref mat 1 0 ))))) (if (zerop d) (quail-error "Cannot invert transform ~S " at) (let ((ox (aref mat 0 2)) (oy (aref mat 1 2)) (sx (aref mat 0 0)) (sy (aref mat 1 1)) (rxy (aref mat 0 1)) (ryx (aref mat 1 0))) (setf (aref new-mat 0 0) (/ sy d) (aref new-mat 1 1) (/ sx d) (aref new-mat 0 1) (/ (- rxy) d) (aref new-mat 1 0) (/ (- ryx) d) (aref new-mat 0 2) (/ (- (* rxy oy) (* sy ox)) d) (aref new-mat 1 2) (/ (- (* ryx ox) (* sx oy)) d)))) new-at)) (defmethod make-affine-transform ((dimension integer)) (let ((array (make-array (list (1+ dimension) (1+ dimension)) :initial-element 0.0))) (dotimes (i (1+ dimension)) (setf (aref array i i) 1.0)) (make-instance 'affine-transform :dimension dimension :affine array))) (defmethod make-affine-transform ((dimension (eql 3))) (change-class (call-next-method) '3d-affine)) (defmethod make-affine-transform ((dimension (eql 2))) (change-class (call-next-method) '2d-affine)) (defmethod x-shift ((affine affine-transform )) (aref (matrix-of affine) 0 2)) (defmethod y-shift ((affine affine-transform )) (aref (matrix-of affine) 1 2)) (defmethod x-scale ((affine affine-transform )) (aref (matrix-of affine) 0 0)) (defmethod y-scale ((affine affine-transform )) (aref (matrix-of affine) 1 1)) (eval-when (eval load) (defvar *identity-2d-transform* (make-affine-transform 2)))
14,774
Common Lisp
.l
307
36.589577
103
0.558271
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
116cba5ede9b73bf8ab5ab9358a33bd76c93e004d0c627c39f3cdc66f55ff283
33,197
[ -1 ]
33,198
stats.lsp
rwoldford_Quail/source/views/utilities/stats.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; stats.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(equisize-bins equicount-bins))) (defvar *projections* nil) ;;;---------------------------------------------------------------------------------- (defun equisize-bins(values nbins &optional label-fn) (if label-fn (setq label-fn (get-function label-fn))) (if (> nbins 0) (let (vmin vmax bin-id ) (loop for v in values maximize v into max minimize v into min finally (setq vmax max vmin min)) (setq bin-id (loop with d = (- vmax vmin) for v in values collect (if (= v vmax) (- nbins 1) (truncate (* (- v vmin) nbins) d)))) (if (null label-fn) bin-id (let ((ordered-values (make-list nbins)) levels) (loop for v in values for b in bin-id do (push v (nth b ordered-values))) (setq levels (loop for v in ordered-values collect (funcall label-fn v))) (loop for x in bin-id collect (nth x levels))))))) (defun equicount-bins(values nbins &optional label-fn) (if label-fn (setq label-fn (get-function label-fn))) (if (> nbins 0) (let* ((values+id (loop for v in values for i upfrom 0 collect (cons v i))) (svalues+id (if (some #'numberp values) (sort values+id #'(lambda(x y) (if (and (numberp x) (numberp y)) (< x y) (numberp x))) :key #'car ) values+id)) (n (length values)) (binsizes (loop with n1 = n for i from 0 below nbins for size = (truncate n1 (- nbins i)) collect size do (decf n1 size))) (svalues (mapcar #'car svalues+id)) (bin-labels (cond ((eq label-fn (get-function 'median)) (loop with start = 0 for size in binsizes collect (eltf svalues (+ start (/ (- size 1) 2))) do (incf start size))) (label-fn (loop with start = 0 for size in binsizes collect (funcall label-fn (subseq svalues start (+ start size))) do (incf start size))) (t (loop for i from 0 below nbins collect i)))) (rep-bin-labels (loop for s in binsizes for b in bin-labels append (make-list s :initial-element b)))) (loop with bins = (make-list n) for b in rep-bin-labels for (s . i) in svalues+id do (setf (nth i bins) b) finally (return bins))) )) (defun map-args (fn values more) (if more (mapcar fn (cons values more)) (funcall fn values))) (defun sum (values &rest more) (map-args #'(lambda (v) (reduce #'+ v)) values more)) (defun eltf(x i) (if (integerp i) (nth i x) (multiple-value-bind(i1 f) (truncate i) (let ((i2 (+ i1 1)) (x1 (nth i1 x))) (+ x1 (* f (- (nth i2 x) x1))))))) #| (defun mean (values &rest more) (map-args #'(lambda (v) (if v (/ (reduce #'+ v) (length v)))) values more)) (defun median (values &rest more) (flet ((med (values) (if values (let* ((vals (sort values #'<))) (eltf vals (/ (- (length vals) 1) 2)))))) (map-args #'med values more))) (defun var (values &rest more) (flet ((var-fn (values) (let ((n (length values)) ) (case n (0 nil) (1 0.0) (t (loop with mean = (/ (reduce #'+ values) n) for v in values sum (* (- v mean) (- v mean)) into ssq finally (return (/ ssq (1- n))))))))) (map-args #'var-fn values more))) (defun sd (values &rest more) (map-args #'(lambda (x) (let ((v (var x))) (if v (sqrt v) nil))) values more)) (defun iqr(values &rest more) (labels ((iqr1(vals) (if vals (let ((five-num (five-num vals))) (- (nth 3 five-num) (nth 1 five-num)))))) (map-args #'iqr1 values more))) |# (defun five-num (values &rest more) (labels ((fun5 (values) (if values (let* ((r (sort values #'<)) (n (- (length r) 1))) (list (elt r 0) (eltf r (/ n 4 )) (eltf r (/ n 2 )) (eltf r (/ (* 3 n) 4 )) (elt r n)))))) (map-args #'fun5 values more))) (defun bp-stats (values &rest more) (labels ( (fun (values) (let* ((n5 (five-num values)) (lq (second n5)) (uq (fourth n5)) (spread (- uq lq)) (lf (- lq (* 1.5 spread))) (uf (+ uq (* 1.5 spread))) lav uav) (loop for x in values do (if (and (>= x lf) (null lav)) (setq lav x)) (if (<= x uf) (setf uav x))) (setf (first n5) lav) (setf (fifth n5) uav) n5))) (map-args #'fun values more))) (defun ssq (x &optional (y x)) (let ((ybar (mean y) ) (xbar (mean x) ) ) (loop for xi in x for yi in y sum (* (- xi xbar) (- yi ybar))))) (defun cov (x y) ;; returns the covariance of x and y (/ (ssq x y) (1- (min (length x) (length y))))) (defun corr (x y) ;; returns the correlation of x and y (/ (cov x y) (sqrt (* (var x) (var y))))) (defun sreg (x y) ;; returns intercept slope sd and se(slope) of simple regresion of y on x (let* ((sxx (ssq x )) (b (/ (ssq x y) sxx)) (a (- (mean y) (* b (mean x)))) (res (loop for xi in x for yi in y collect (- yi (+ a (* b xi))))) (sd (sqrt (/ (ssq res) (- (length res) 2))))) (list a b sd (/ sd (sqrt sxx)) ))) ;;;---------------------------------------------------------------------------- (defun copy-matrix (a) (let* ((m (array-dimension a 0)) (n (array-dimension a 1)) (copy-a (make-array (list m n)))) ; (loop for i from 0 below m do (do ((i 0 (incf i))) ((= i m)) ; (loop for j from 0 below n do (do ((j 0 (incf j))) ((= j n)) (setf (aref copy-a i j) (aref a i j)))) copy-a)) (defun transpose-matrix (a) (let* ((m (array-dimension a 0)) (n (array-dimension a 1)) (trans-a (make-array (list n m)))) ; (loop for i from 0 below m do (do ((i 0 (incf i))) ((= i m)) ; (loop for j from 0 below n do (do ((j 0 (incf j))) ((= j n)) (setf (aref trans-a j i) (aref a i j)))) trans-a)) (defun mult-matrix (a b) (let* ((m (array-dimension a 0)) (n (array-dimension a 1)) (p (array-dimension b 1)) (res (make-array (list m p)))) ; (loop for i from 0 below m do (do ((i 0 (incf i))) ((= i m)) ; (loop for j from 0 below p do (do ((j 0 (incf j))) ((= j p)) (setf (aref res i j) ; (loop for k from 0 below n sum (do ((sum-a 0) (k 0 (incf k))) ((= k n) sum-a) (incf sum-a (* (aref a i k) (aref b k j))))))) res)) (defun qr (a) ;; returns q orthogonal and r upper-triang (let* ((m (array-dimension a 0)) (n (array-dimension a 1)) (r (make-array (list n n) :initial-element 0)) (q (copy-matrix a))) ; (loop for k from 0 below n do (do ((k 0 (incf k))) ((= k n)) (setf (aref r k k) (sqrt ; (loop for i from 0 below m sum (do ((sum-q 0) (i 0 (incf i))) ((= i m) sum-q) (incf sum-q (* (aref q i k) (aref q i k)))))) ; (loop for i from 0 below m do (do ((i 0 (incf i))) ((= i m)) (setf (aref q i k) (/ (aref q i k) (aref r k k)))) ; (loop for j from (+ 1 k) below n do (do ((j (1+ k) (incf j))) ((= j n)) (setf (aref r k j) ; (loop for i from 0 below m sum (do ((sum-q 0) (i 0 (incf i))) ((= i m) sum-q) (* (aref q i k) (aref q i j))) ) ; (loop for i from 0 below m do (do ((i 0 (incf i))) ((= i m)) (decf (aref q i j) (* (aref q i k) (aref r k j)))))) (values q r))) ;;==================== #| ;; a, aq ar ;; test orthog of aq (multiple-value-setq (aq ar) (qr a)) (setq qtq (mult-matrix (transpose-matrix aq) aq)) (setq q-r (mult-matrix aq ar)) (loop for i from 0 below 8 do (quail-print (aref qtq i i))) (loop for i from 0 below 8 maximize (loop for j from 0 below 8 unless (= i j) maximize (aref qtq i j))) (loop for i from 0 below 10 maximize (loop for j from 0 below 8 maximize (abs (- (aref a i j) (aref q-r i j))))) |# ;;=============================================================== (defun q-matrix (x &optional cols rows ) ;; X is a list of lists (rows) ;; returns an orthog matrix whose cols span col-space of ;; X (if (null cols) (setq cols (loop for i from 0 below (length (first x)) collect i))) (if rows (setq x (if (and (not (null rows)) (listp rows)) (loop for xi in x for ri in rows when ri collect xi) (loop for xi in x when (funcall rows xi) collect xi)))) (let ((n (length x)) (p (length cols)) x-mat ) (setq x-mat (make-array (list n p) )) (loop for i from 0 below n for xi in x do (loop for j from 0 below p for k in cols do (setf (aref x-mat i j) (elt xi k)))) (qr x-mat))) (defun orthog-comp (x) (let* ((n (array-dimension x 0)) (x-comp (make-array (list n n)))) (loop for i from 0 below n do (loop for j from 0 below n do (setf (aref x-comp i j) (if (= i j) (- 1 (aref x i j)) (- (aref x i j)))))) x-comp)) (defun make-projector (mat &optional name inverse?) (unless name (setq name "PROJECTOR")) (let ((p (list mat name inverse?))) (push p *projections*) p)) (defun make-orthog-projector (mat &optional name ) (unless name (setq name "PROJECTOR")) (setq name (concatenate 'string "ORTH " name)) (make-projector mat name 'orthog)) (defun projector-matrix(p) (car p)) (defun projector-name(p) (second p)) (defun projector-dim(p) (array-dimension (car p) 0)) (defun orthog-p (p ) (third p)) (defun apply-projector (p seq) (let* ((mat (projector-matrix p)) (n (array-dimension mat 0)) (m (array-dimension mat 1)) pt*seq result) (if (not (= (length seq) n)) seq (progn (setq pt*seq (loop for j from 0 below m collect (loop for i from 0 below n sum (* (elt seq i) (aref mat i j))))) (setq result (loop for i from 0 below n collect (loop for j from 0 below m for sj in pt*seq sum (* sj (aref mat i j))))) (if (orthog-p p) (setq result (loop for r in result for i from 0 below n collect (- (elt seq i) r)))) (if (vectorp seq) (make-array n :initial-contents result) result))))) (defun make-projection-for-vars (x name &key cols rows (orthog-too? t)) (let ((p (q-matrix x cols rows))) (if orthog-too? (values (make-projector p name) (make-orthog-projector p name )) (make-projector p name)))) (defun array-to-lists (a) (loop for i from 0 below (array-dimension a 0) collect (loop for j from 0 below (array-dimension a 1) collect (aref a i j))))
14,096
Common Lisp
.l
369
25.693767
102
0.42697
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4cc1a641bae53004dd20f5b01d89f60f3f6072f79d52e615831777b27f69efe0
33,198
[ -1 ]
33,199
fasttrans.lsp
rwoldford_Quail/source/views/utilities/fasttrans.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; fasttrans.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-affine-transform affine-trans-p dimension-of matrix-of apply-transform apply-transform! compose-transforms error-mismatched-dimensions premultiply-transform! rotate-transform! set-to-identity scale-transform! translate-transform! invert-transform *identity-2d-transform*))) (defun make-affine-transform (dimension) (let ((array (make-array (list (1+ dimension) (1+ dimension)) :element-type 'real :initial-element 0.0))) (dotimes (i (1+ dimension)) (setf (aref array i i) 1.0)) array )) (defun affine-trans-p (affine) (and (typep affine 'array) (= (array-rank affine) 2))) (defun dimension-of (affine) (- (array-dimension affine 0) 1)) (defun matrix-of (affine) affine) (defun affine-copy (affine) (let* ((size (dimension-of affine)) (new (make-affine-transform size))) (dotimes (i (1+ size)) (dotimes (j (1+ size)) (setf (aref new i j) (aref affine i j)))) new)) (defun x-shift (affine) (aref affine 0 2)) (defun y-shift (affine) (aref affine 1 2)) (defun x-scale (affine) (aref affine 0 0)) (defun y-scale (affine) (aref affine 1 1)) (eval-when (:execute :load-toplevel) ;(eval load) 09MAR2022 gwb (defvar x-scale(make-affine-transform 2))) (defun apply-transform (self item) ;;; applies the TRANSFORM self to ITEM , returning the resulting ;;; 2d-POSITION /REGION/LIST (if (region-p item) (let* ((top-right (apply-transform self (top-right-of item))) (bottom-left (apply-transform self (bottom-left-of item))) (l (2d-position-x bottom-left)) (r (2d-position-x top-right)) (b (2d-position-y bottom-left)) (tp (2d-position-y top-right))) (if (> l r) (rotatef l r)) (if (> b tp) (rotatef b tp)) (make-region l r b tp)) ;;else (multiple-value-bind (x y) (if (2d-position-p item) (values (2d-position-x item) (2d-position-y item)) (values (first item) (second item))) (let ((mat (matrix-of self)) new-x new-y) (setq new-x (+ (* x (aref mat 0 0)) (* y (aref mat 0 1)) (aref mat 0 2))) (setq new-y (+ (* x (aref mat 1 0)) (* y (aref mat 1 1)) (aref mat 1 2))) (if (listp item) (list new-x new-y) (make-2d-position new-x new-y)))))) (defun apply-transform! (at item) ;;; applies the 2D-AFFINE at to ITEM, placing results in ITEM arguments (let ((top-right (apply-transform at (top-right-of item))) (bottom-left (apply-transform at (bottom-left-of item)))) (setf (bounds-of item) (list (2d-position-x bottom-left) (2d-position-x top-right) (2d-position-y bottom-left) (2d-position-y top-right))) item)) (defun compose-transforms (at1 at2) ;;; composes AFFINE-TRANSFORMs AT1 with AT2 , returning the resulting ;;; AFFINE-TRANSFORM (if (not (eql (dimension-of at1) (dimension-of at2))) (error-mismatched-dimensions at1 at2) ;; else (let* ((size (dimension-of at1)) (result (make-affine-transform size)) (mat1 (matrix-of at1)) (mat2 (matrix-of at2)) (mat3 (matrix-of result))) ; (loop for i from 0 to size do (do ((i 0 (incf i))) ((> i size)) ; (loop for j from 0 to size do (do ((j 0 (incf j))) ((> j size)) (setf (aref mat3 i j) ; (loop for k from 0 to size sum (do ((sum-mat3 0) (k 0 (incf k))) ((> k size) sum-mat3) (incf sum-mat3 (* (aref mat1 i k) (aref mat2 k j))))))) result))) (defun error-mismatched-dimensions (at1 at2) (quail-error "The transforms ~S and ~S do not have matching dimensions" at1 at2)) (defun premultiply-transform! (at multiplier) ;;; premultiply AFFINE-TRANSFORM AT by another AFFINE-TRANSFORM, MULTIPLIER, ;;; storing result in AT (if (not (eql (dimension-of at) (dimension-of multiplier))) (error-mismatched-dimensions at multiplier) ;; else (let* ((size (1+ (dimension-of at))) (at-copy (affine-copy at)) (mat3 (matrix-of at-copy)) (mat1 (matrix-of at)) (mat2 (matrix-of multiplier))) (dotimes (i size) (dotimes (j size) (setf (aref mat1 i j) 0.0) (dotimes (k size) (incf (aref mat1 i j) (* (aref mat2 i k) (aref mat3 k j)))))) )) at) (defun rotate-transform! (self angle &optional (radians? nil)) ;; rotates the 2D-AFFINE SELF by ANGLE (unless radians? (setq angle (/ angle 180.0))) (let* ((c (cos angle)) (s (sin angle)) (mat (matrix-of self)) (a00 (aref mat 0 0)) (a01 (aref mat 0 1)) (a10 (aref mat 1 0)) (a11 (aref mat 1 1))) (setf (aref mat 0 0) (- (* c a00) (* s a10))) (setf (aref mat 0 1) (- (* c a01) (* s a11))) (setf (aref mat 1 0) (+ (* c a00) (* s a10))) (setf (aref mat 1 1) (+ (* c a01) (* s a11))))) (defun set-to-identity (self) ;; the AFFINE-TRANSFORM SELF becomes the identity (let* ((matrix self) (dim (array-dimension matrix 0))) (dotimes (i dim) (dotimes (j dim) (setf (aref matrix i j) 0.0)) (setf (aref matrix i i) 1.0)))) (defun scale-transform! (self scale &rest other-scales) ;; scales the AFFINE-TRANSFORM SELF by SCALES in the x-direction and by ;; OTHER-SCALES in the remaining directions. If OTHER-SCALES is not ;; present,SCALE is applied in all to directions (let ((scale-list (if other-scales (cons scale other-scales) (make-list (dimension-of self) :initial-element scale))) (mat (matrix-of self))) (loop for scale-amt in scale-list for i upfrom 0 do ; (loop for j from 0 to (dimension-of self) do (let ((dos (dimension-of self))) (do ((j 0 (incf j))) ((> j dos)) (setf (aref mat i j) (* (aref mat i j) scale-amt))))))) (defun translate-transform! (self delta &rest other-deltas) ;; translates the AFFINE-TRANSFORM SELF by DELTA in the x-direction ;; and by OTHER-DELTAS in the other directions. If OTHER-DELTAS are ;; not present,DELTA is applied to all directions (loop with dim = (dimension-of self) with mat = (matrix-of self) with delta-list = (if other-deltas (cons delta other-deltas) (make-list dim :initial-element delta)) for delta-amt in delta-list for i upfrom 0 do (incf (aref mat i dim) delta-amt))) (defun invert-transform (at ) ;; inverts the transform at (let* ((size (dimension-of at)) (new-at (make-affine-transform size)) (mat (matrix-of at)) (new-mat (matrix-of new-at)) (d (- (* (aref mat 0 0 ) (aref mat 1 1 )) (* (aref mat 0 1 ) (aref mat 1 0 ))))) (if (zerop d) (quail-error "Cannot invert transform ~S " at) (let ((ox (aref mat 0 2)) (oy (aref mat 1 2)) (sx (aref mat 0 0)) (sy (aref mat 1 1)) (rxy (aref mat 0 1)) (ryx (aref mat 1 0))) (setf (aref new-mat 0 0) (/ sy d) (aref new-mat 1 1) (/ sx d) (aref new-mat 0 1) (/ (- rxy) d) (aref new-mat 1 0) (/ (- ryx) d) (aref new-mat 0 2) (/ (- (* rxy oy) (* sy ox)) d) (aref new-mat 1 2) (/ (- (* ryx ox) (* sx oy)) d)))) new-at)) (eval-when (:execute :load-toplevel) ;(eval load) 09MAR2022 gwb (defvar *identity-2d-transform* (make-affine-transform 2)))
8,977
Common Lisp
.l
208
33.442308
127
0.5295
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
65da17bc2dade18049fa499f543a52be98d8a95d29f50a6517c0fdaf443022ac
33,199
[ -1 ]
33,200
numerical-label.lsp
rwoldford_Quail/source/views/simple-views/numerical-label.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; numerical-label.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1997 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(numerical-label set-numerical-format))) (defclass numerical-label (label) ((number :initarg :number :reader numerical-value-of :initform nil :documentation "Number being displayed as text.") (format :initarg :format :reader format-of :initform "~s" :documentation "Format string to be used to create text from number.") (style-keys :initform '(:font :color) :allocation :class) (middle-menu :allocation :class :initform nil)) (:documentation "A linkable label to display numerical values.") (:default-initargs :font *default-label-font* :linkable? t :justification :right :orientation :horizontal)) (defmethod initialize-instance :after ((self numerical-label) &rest initargs &key (format NIL format?)) (declare (ignore initargs)) (cond ((eq format :prompt) (set-numerical-format self NIL :draw? NIL)) ((and format? (null format)) (setf (format-of self) "~s")) ) (unless (viewed-object-of self) (setf (viewed-object-of self) (numerical-value-of self))) (setf (text-of self) (format NIL (format-of self) (numerical-value-of self))) ) (defmethod (setf numerical-value-of) (new-value (self numerical-label)) (when (eq new-value :prompt) (setq new-value (wb:prompt-user :result-type 'number :prompt-string "Enter numerical value"))) (let ((drawn? (viewports-of self))) (when (numberp new-value) (if drawn? (erase-view self)) (if (and (numberp (viewed-object-of self)) (= (viewed-object-of self) (numerical-value-of self))) (setf (viewed-object-of self) new-value)) (setf (slot-value self 'number) new-value) (setf (text-of self) (format NIL (format-of self) new-value)) (if drawn? (draw-view self)) ) )) (defmethod (setf format-of) (new-value (self numerical-label)) (let ((drawn? (viewports-of self))) (cond ((eq new-value :prompt) (set-numerical-format self NIL :draw? drawn?)) ((stringp new-value) (if drawn? (erase-view self)) (setf (text-of self) (format NIL new-value (numerical-value-of self))) (setf (slot-value self 'format) new-value) (if drawn? (draw-view self)) ) ((wb::prompt-t-or-f (format NIL "New value (~s) for format is not a string. ~& Would you like to construct one now?" new-value)) ;;; spce added after ~& 12MAR2022 gwb (set-numerical-format self NIL :draw? drawn?) )))) (defmethod get-menu-items ((self numerical-label) (slot-name (eql 'middle-menu))) `(("Numerical format" (set-numerical-format nil :viewport)) )) (defmethod draw-view :before ((self numerical-label) &key number text viewport) (declare (ignore number text viewport)) ) (defmethod set-numerical-format ((self numerical-label) format &key viewport (draw? t)) (unless format (let* ((pos (prompt-position self viewport)) (format-types '("Lisp format directive" "Fixed-format floating point" "Exponential floating point" "Dollars floating point" "General floating point" "Decimal" "Binary" "Octal" "Hexadecimal" "Radix" )) (format-type (wb:pick-one format-types)) ) (cond ((string-equal format-type "Lisp format directive") (setf format (wb:prompt-user :result-type 'string :read-type :eval :prompt-string (format nil "Format directive string:") :left (2d-position-x pos) :top (2d-position-y pos)))) ((string-equal format-type "Fixed-format floating point") (setf format "~") (setf format-type (wb:collect-input '(("Width in characters" ) ("Digits after decimal place" ) ("Scale factor" ) ("Overflow character" ) ("Pad character" ) ) :prompt-text (format NIL "Fixed-format floating point. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((string-equal (car pair) "Overflow character") (concatenate 'string format (format NIL "'~a" (cdr pair)) ",") ) ((string-equal (car pair) "Pad character") (concatenate 'string format (format NIL "'~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ","))) (concatenate 'string format ",")))) (setf format (concatenate 'string format "F")) ) ((string-equal format-type "Exponential floating point") (setf format "~") (setf format-type (wb:collect-input '(("Width in characters" ) ("Digits after decimal place" ) ("Digits for exponent" ) ("Scale factor" ) ("Overflow character" ) ("Pad character" ) ("Exponent character" ) ) :prompt-text (format NIL "Exponential floating point. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Overflow character") (string-equal (car pair) "Pad character") ) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",") ) ((string-equal (car pair) "Exponent character") (concatenate 'string format (format NIL "'~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ","))) (concatenate 'string format ",")))) (setf format (concatenate 'string format "E")) ) ((string-equal format-type "Decimal") (setf format "~") (setf format-type (wb:collect-input '(("Width in columns" ) ("Pad character" ) ("Comma character" ) ("Interval between commas" ) ) :prompt-text (format NIL "Decimal. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Pad character") (string-equal (car pair) "Comma character")) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",")) ((string-equal (car pair) "Interval between commas") (concatenate 'string format (format NIL "~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ",")) ) (concatenate 'string format ",")))) (setf format (concatenate 'string format "D")) ) ((string-equal format-type "Binary") (setf format "~") (setf format-type (wb:collect-input '(("Width in columns" ) ("Pad character" ) ("Comma character" ) ("Interval between commas" ) ) :prompt-text (format NIL "Binary. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Pad character") (string-equal (car pair) "Comma character")) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",")) ((string-equal (car pair) "Interval between commas") (concatenate 'string format (format NIL "~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ",")) ) (concatenate 'string format ",")))) (setf format (concatenate 'string format "B")) ) ((string-equal format-type "Octal") (setf format "~") (setf format-type (wb:collect-input '(("Width in columns" ) ("Pad character" ) ("Comma character" ) ("Interval between commas" ) ) :prompt-text (format NIL "Octal. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Pad character") (string-equal (car pair) "Comma character")) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",")) ((string-equal (car pair) "Interval between commas") (concatenate 'string format (format NIL "~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ",")) ) (concatenate 'string format ",")))) (setf format (concatenate 'string format "O")) ) ((string-equal format-type "Hexadecimal") (setf format "~") (setf format-type (wb:collect-input '(("Width in columns" ) ("Pad character" ) ("Comma character" ) ("Interval between commas" ) ) :prompt-text (format NIL "Hexadecimal. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Pad character") (string-equal (car pair) "Comma character")) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",")) ((string-equal (car pair) "Interval between commas") (concatenate 'string format (format NIL "~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ",")) ) (concatenate 'string format ",")))) (setf format (concatenate 'string format "X")) ) ((string-equal format-type "Radix") (setf format "~") (setf format-type (wb:collect-input '(("Radix" ) ("Width in columns" ) ("Pad character" ) ("Comma character" ) ("Interval between commas" ) ) :prompt-text (format NIL "Radix. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Pad character") (string-equal (car pair) "Comma character")) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",")) ((string-equal (car pair) "Interval between commas") (concatenate 'string format (format NIL "~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ",")) ) (concatenate 'string format ",")))) (setf format (concatenate 'string format "R")) ) ((string-equal format-type "Dollars floating point") (setf format "~") (setf format-type (wb:collect-input '(("Digits after decimal place" ) ("Minimum number of digits before decimal") ("Minimum total width" ) ("Pad character" ) ) :prompt-text (format NIL "Dollars floating point. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (if (string-equal (car pair) "Pad character") (concatenate 'string format (format NIL "'~a" (cdr pair)) ) (concatenate 'string format (format NIL "~a" (cdr pair)) ",")) (concatenate 'string format ",")))) (setf format (concatenate 'string format "$")) ) ((string-equal format-type "General floating point") (setf format "~") (setf format-type (wb:collect-input '(("Width in characters" ) ("Digits after decimal place" ) ("Digits for exponent" ) ("Scale factor" ) ("Overflow character" ) ("Pad character" ) ("Exponent character" ) ) :prompt-text (format NIL "General floating point. ~% Fill in values as appropriate:") )) (loop for pair in format-type do (setf format (if (cdr pair) (cond ((or (string-equal (car pair) "Overflow character") (string-equal (car pair) "Pad character") ) (concatenate 'string format (format NIL "'~a" (cdr pair)) ",") ) ((string-equal (car pair) "Exponent character") (concatenate 'string format (format NIL "'~a" (cdr pair)) )) (T (concatenate 'string format (format NIL "~a" (cdr pair)) ","))) (concatenate 'string format ",")))) (setf format (concatenate 'string format "G")) ) (T (setf format (wb:prompt-user :result-type 'string :read-type :eval :prompt-string (format nil "Format directive string:") :left (2d-position-x pos) :top (2d-position-y pos)))) ) ) ) (setf (format-of self) format) (if draw? (draw-view self :erase? t)))
20,743
Common Lisp
.l
482
21.634855
110
0.36252
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
87893abc0486b176ab713ac9fc58b6e27810ef50c89bae0f704ec0ae3ebfd940
33,200
[ -1 ]
33,201
editable-text.lsp
rwoldford_Quail/source/views/simple-views/editable-text.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; editable-text.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views statistical graphics package. ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1996 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(editable-text-view))) (defclass editable-text-view (text-view key-input-view) ((between-words? :initform NIL :accessor break-between-words :documentation "A flag for draw-view to indicate how overflow lines should ~ break when displayed. If non-NIL then the display will break ~ the line just before the overflowing word, otherwise just ~ before the overflowing character. Default is NIL.") (pos-&-chars :initform NIL :accessor character-positions :documentation "An association list indexed by viewport. Each value is ~ a list of rows ~ where each row is itself a list the first element ~ of which is the y-position ~ and whose remaining elements are the ~ (position string-index character) triples for each character in ~ the text string. The list is in the reverse order to the ~ order of the characters in the display.~%~ It is constructed whenever the view is drawn.") (input-color :initform wb:*black-color* :accessor input-color :documentation "The colour to be used as the drawing colour for the ~ editable text when input is active.") (input-back-color :initform *default-highlight-color* :accessor input-back-color :documentation "The colour to be used as the background colour for the ~ editable text when input is active.") ) (:documentation " A text-view whose text can be altered by keyboard input.") ) ;;; ;;; The following is a utility function used by draw-view and by handle-key-event ;;; (defun draw-&-return-pos-info (editable-text-view viewport &key string (counter 0)) (let* ((self editable-text-view) (col (if (input-mode-p self) (input-color self) (draw-style self :color))) (font (draw-style self :font)) (pos-in-string (- counter 1)) (start 0) (break-between-words? (break-between-words self)) (results-by-vp NIL) ) (unless string (setf string (get-text self))) (flet ((read-word (string) (If (> start (length string)) nil (let* ((pos-space (position #\Space string :test #'char= :start start)) (pos-line (position #\Newline string :test #'char= :start start)) result to-newline?) (cond ((and pos-line pos-space) (cond ((< pos-line pos-space) (setq result (subseq string start pos-line)) (setq start (+ 1 pos-line)) (setq to-newline? T)) (T (setq result (subseq string start (+ 1 pos-space))) (setq start (+ 1 pos-space))))) (pos-space (setq result (subseq string start (+ 1 pos-space))) (setq start (+ 1 pos-space))) (pos-line (setq result (subseq string start pos-line)) (setq start (+ 1 pos-line)) (setq to-newline? T)) (T (setq result (subseq string start)) (setq start (+ 1 (length string))))) (cons result to-newline?))))) (with-exposed-viewports self viewport vp (let* ((w (window-of vp)) (pos-by-y NIL) (x-pos-&-chars NIL) (leading (wb:canvas-font-leading w :font font)) (descent (wb:canvas-font-descent w :font font)) (ascent (wb:canvas-font-ascent w :font font)) (height (+ leading ascent descent)) (input-pos (cdr (assoc vp (input-positions self)))) ) (wb:with-pen-color w col (wb:with-canvas-font w font (multiple-value-bind (l r b tp ) (bounds-of vp) (cond (input-pos (wb:canvas-move-to w (wb:position-x input-pos) (wb:position-y input-pos))) (T (setf input-pos (wb:make-position l (- tp ascent))) (wb:canvas-move-to w l (- tp ascent)) )) (loop for (word . newline) = (read-word string) until (or (and (null word) (null newline) ;; <------------------here ) (< (- (wb:canvas-y w) descent) b)) do (cond (break-between-words? (when (> (wb:canvas-string-width w word :font font) (- r (wb:canvas-x w))) (push (cons (wb:canvas-y w) x-pos-&-chars) pos-by-y) (setf x-pos-&-chars NIL) (wb:canvas-move-to w l (- (wb:canvas-y w) height))) (do ((char) (i 0 (1+ i))) ((= i (length word))) (setf char (elt word i)) (push (list (wb:canvas-x w) (incf pos-in-string) char) x-pos-&-chars) (wb:canvas-draw-character w char))) (T (do ((char) (i 0 (1+ i))) ((= i (length word))) (setf char (elt word i)) (when (> (wb:canvas-string-width w (string char) :font font) (- r (wb:canvas-x w))) (push (cons (wb:canvas-y w) x-pos-&-chars) pos-by-y) (setf x-pos-&-chars NIL) (wb:canvas-move-to w l (- (wb:canvas-y w) height)) ) (push (list (wb:canvas-x w) (incf pos-in-string) char) x-pos-&-chars) (wb:canvas-draw-character w char) ))) (when newline ;; stick the newline character on the end of the present line (push (list (wb:canvas-x w) (incf pos-in-string) #\NewLine) x-pos-&-chars) ;; end the current line (push (cons (wb:canvas-y w) x-pos-&-chars) pos-by-y) ;; move to beginning of new line (wb:canvas-move-to w l (- (wb:canvas-y w) height)) ;; start newline (setf x-pos-&-chars NIL) ) finally (push (cons (wb:canvas-y w) x-pos-&-chars) pos-by-y) )))) (setf input-pos (wb:make-position (wb:canvas-x w) (wb:canvas-y w))) (push (list vp (cons :input-position input-pos) (cons :positions pos-by-y)) results-by-vp) )) ) results-by-vp)) (defmethod draw-view ((self editable-text-view) &key viewport) ;; get rid of the input-positions so that the drawing will start from ;; the natural origin. (when (viewports-of self) (setf (input-positions self) NIL)) (let ((results NIL)) (setf results (draw-&-return-pos-info self viewport)) (when results ;; Now tuck the results away on self (loop for result in results do (let* ((vp (car result)) (info (rest result)) (input-pos (cdr (assoc :input-position info))) (positions (cdr (assoc :positions info)))) (if (assoc vp (character-positions self)) (setf (cdr (assoc vp (character-positions self))) positions) (push (cons vp positions) (character-positions self))) (if (assoc vp (input-positions self)) (setf (cdr (assoc vp (input-positions self))) input-pos) (push (cons vp input-pos) (input-positions self))) ))))) (defun erase-input-mark (self viewport) (let ((back-color (input-back-color self))) (with-exposed-viewports self viewport vp (let* ((w (window-of vp)) (font (draw-style self :font)) (descent (wb:canvas-font-descent w :font font)) (ascent (wb:canvas-font-ascent w :font font)) (input-pos (cdr (assoc vp (input-positions self)))) ) (unless (input-mode-p self) (setf back-color (wb:canvas-background-color w))) (multiple-value-bind (l r b tp ) (bounds-of vp) (declare (ignore b r)) (when (null input-pos) ;; Should never happen. (setf input-pos (wb:make-position l (- tp ascent)))) (wb::canvas-draw-line w (wb:position-x input-pos) (- (wb:position-y input-pos) descent) (wb:position-x input-pos) (+ (wb:position-y input-pos) ascent -1) :color back-color) ))))) (defun draw-input-mark (self viewport) (let ((input-color (input-color self))) (with-exposed-viewports self viewport vp (let* ((w (window-of vp)) (font (draw-style self :font)) (descent (wb:canvas-font-descent w :font font)) (ascent (wb:canvas-font-ascent w :font font)) (input-pos (cdr (assoc vp (input-positions self)))) ) (unless (input-mode-p self) (setf input-color (draw-style self :color))) (multiple-value-bind (l r b tp ) (bounds-of vp) (declare (ignore b r)) (when (null input-pos) ;; Should never happen. (setf input-pos (wb:make-position l (- tp ascent)))) (wb::canvas-draw-line w (wb:position-x input-pos) (- (wb:position-y input-pos) descent) (wb:position-x input-pos) (+ (wb:position-y input-pos) ascent -1) :color input-color) ))))) (defmethod stop-input ((self editable-text-view) viewport) (erase-input-mark self viewport) ) (defmethod stop-input :after ((self editable-text-view) viewport) (clear-view-viewport self :viewport viewport) (draw-view self :viewport viewport)) (defmethod start-input ((self editable-text-view) viewport) (draw-input-mark self viewport)) ;;; the next method replaces the 3 block-commented out below it 29SEP2023 gwb (defmethod end-event-input-p ((view editable-text-view) (event T)) (declare (ignorable view event)) (cond ((eql event wb:+enter-key-event+) T) ((eql event wb:+escape-key-event+) T) (T nil))) #| (defmethod end-event-input-p ((view editable-text-view) (event T)) ;T)) 18SEP2023 (declare (ignorable view event)) ;(declare (ignore view event)) ;29JUL2023 NIL) (defmethod end-event-input-p ((view editable-text-view) (event (eql wb:+enter-key-event+))) ;wb:*enter-key-event*))) 23FEB2022 gwb (declare (ignorable view event)) ;(declare (ignore view event)) ;29JUL2023 T) (defmethod end-event-input-p ((view editable-text-view) (event (eql wb:+escape-key-event+))) ;wb:*escape-key-event*))) 23FEB2022 gwb (declare (ignorable view event)) ;(declare (ignore view event)) ; 28JUL2023 T) |# (defmethod refocus-input ((self editable-text-view) viewport &optional position) "Moves the focus of the input to a new location determined from the ~ given position." (with-exposed-viewports self viewport vp (let* ((w (window-of vp)) (font (draw-style self :font)) (descent (wb:canvas-font-descent w :font font)) (ascent (wb:canvas-font-ascent w :font font)) (input-pos (cdr (assoc vp (input-positions self)))) (character-positions (cdr (assoc vp (character-positions self)))) (last-y (first (first character-positions))) (last-x (first (second (first character-positions)))) rows-before input-row chars-before input-pos-x input-pos-y pos-x pos-y ) (multiple-value-bind (l r b tp ) (bounds-of vp) (declare (ignore r b)) (unless last-x (setf last-x l)) (unless last-y (setf last-y (- tp ascent))) (cond ((or (null input-pos) (null character-positions)) ;; no characters, starting input (setf input-pos-x l input-pos-y (- tp ascent)) ) (T ;; erase the current input mark, if there is one. (erase-input-mark self vp) ;; local-vars (setf input-pos-x (wb:position-x input-pos) input-pos-y (wb:position-y input-pos)) (setf pos-x (wb:position-x position) pos-y (wb:position-y position)) ;; Need to determine which character is immediately before (cond ((< pos-y (- last-y descent)) ;; then it's past the last line, so place the input position after the ;; last character. (setf input-pos-y last-y) (setf input-pos-x ;; sum last-x and the character's width (+ last-x (if (third (second (first character-positions))) (wb:canvas-character-width w ;; last-char (third (second (first character-positions))) :font font) 0))) ) (T ;; Determine input row (setf rows-before (member-if #'(lambda (row) (< pos-y (+ (car row) ascent))) character-positions)) (setf input-row (car rows-before)) ;; Here are the true rows before (setf rows-before (cdr rows-before)) ;; ;; get the characters before the input in the same row. ;; (setf chars-before (member-if #'(lambda (x) (< (+ (car x) (wb:canvas-character-width w (third x) :font font)) pos-x)) (cdr input-row))) ;; ;; the location of the character before the input-position ;; is either in this row; or if the input is before the first ;; character then we need to go to the end of the previous row. ;; (cond (chars-before ;; The y location (setf input-pos-y (first input-row)) ;; The X location (setf input-pos-x (+ ;; sum previous character's x position (first (first chars-before)) ;; and it's width (wb:canvas-character-width w ;; the char (third (first chars-before)) :font font) )) ) (rows-before ;; No characters precede the position in this row ;; Move to after the last character in the row before (setf input-pos-y (first (first rows-before))) (setf input-pos-x (+ (first (second (first rows-before))) (wb:canvas-character-width w ;; the char (third (second (first rows-before))) :font font))) ) (T ;; Must be at the beginning (setf input-pos-x l input-pos-y (- tp ascent))) ) ) ) ) ) ) ;; Got the new input position (setf input-pos (wb:make-position input-pos-x input-pos-y)) ;; Store it away (if (assoc vp (input-positions self)) (setf (cdr (assoc vp (input-positions self))) input-pos) (push (cons vp input-pos) (input-positions self))) ;; Indicate where the input position is in the display (draw-input-mark self vp) ) ) ) (defmethod handle-key-event ((self editable-text-view) (char character)) "Inserts the characters at the current position." (let ((col (draw-style self :color)) (font (draw-style self :font))) (with-exposed-viewports self NIL vp (let* ((w (window-of vp)) (leading (wb:canvas-font-leading w :font font)) (descent (wb:canvas-font-descent w :font font)) (ascent (wb:canvas-font-ascent w :font font)) (height (+ leading ascent descent)) (input-pos (cdr (assoc vp (input-positions self)))) (character-positions (cdr (assoc vp (character-positions self)))) (last-index (second (second (find-if #'(lambda (row) (not (null (cdr row)))) character-positions)))) (last-y (first (first character-positions))) (last-x (first (second (first character-positions)))) (rows-before NIL) (input-row NIL) (chars-before NIL) (input-index NIL) (input-pos-x NIL) (input-pos-y NIL) back-color) (cond ((input-mode-p self) (setf back-color (input-back-color self)) (setf col (input-color self)) ) (T (setf back-color (wb:canvas-background-color w)))) (wb:with-pen-color w col (wb:with-canvas-font w font (multiple-value-bind (l r b tp ) (bounds-of vp) (unless (wb:position-p input-pos) (setf input-pos (wb:make-position l (- tp ascent)))) (unless last-x (setf last-x l)) (unless last-y (setf last-y (- tp ascent))) (setf input-pos-x (wb:position-x input-pos) input-pos-y (wb:position-y input-pos)) (wb:canvas-move-to w input-pos-x input-pos-y) ;; ;; first get the rows that are OK. ;; (when character-positions (setf rows-before (member-if #'(lambda (row) (= (car row) input-pos-y)) character-positions))) (setf input-row (car rows-before)) (setf rows-before (cdr rows-before)) ;; ;; get the characters before the input in the same row. ;; (when input-row (setf chars-before (member-if #'(lambda (x) (< (car x) input-pos-x)) (cdr input-row)))) ;; ;; get the index of the character before the input-position ;; in the string ;; (cond (chars-before (setf input-index (second (first chars-before)))) (rows-before ;; We pop to the previous line (setf input-index (second (second (first rows-before))))) (T (setf input-index NIL)) ) ;; ;; Deletion of previous character must be treated differently from ;; simply adding characters. ;; (if (member char (list wb:+rubout-event+ wb:+delete-event+)) ;wb:*rubout-event* wb:*delete-event*)) 23FEB2022 gwb (cond ((null last-index) ;; Nothing is here, delete is bogus. ;; Set input-pos and character-positions properly ;; (setf input-pos-x l input-pos-y (- tp ascent)) ;; tuck it away (setf (cdr (assoc vp (input-positions self))) (wb:make-position input-pos-x input-pos-y)) ;; blow away character positions (when (assoc vp (character-positions self)) (setf (cdr (assoc vp (character-positions self))) NIL)) ) ((null input-index) ;; Nothing is before, delete is bogus. just set input-pos right. (setf input-pos-x l input-pos-y (- tp ascent)) ;; tuck it away (setf (cdr (assoc vp (input-positions self))) (wb:make-position input-pos-x input-pos-y)) ) ((zerop input-index) ;; delete first character, just erase all, delete, redraw (erase-view self :viewport vp) (setf (text-of self) (subseq (get-text self) 1)) (draw-view self :viewport vp) (setf input-pos-x ;; x value of (first ;;first character (first (last ; was second?! ;; in first row (first (last character-positions)))) ) input-pos-y ;; y value of (first ;; first row (first (last character-positions)))) ;; tuck it away (setf (cdr (assoc vp (input-positions self))) (wb:make-position input-pos-x input-pos-y)) ) ((= input-index last-index) (erase-input-mark self vp) ;; delete last character (setf (text-of self) (subseq (get-text self) 0 last-index)) (wb:canvas-draw-filled-rectangle w last-x r (- last-y descent) (+ last-y ascent) :color back-color) ;; ;; Move back to previous character's position (setf input-pos-x last-x) (setf input-pos-y last-y) ;; ;; Update character-positions ;; (setf (first character-positions) (cons ;; y of last row (first (first character-positions)) ;; strip off last character of the rest of that row (rest (rest (first character-positions))))) ;; ;; Move back to previous line if we deleted the current line ;; (when (and rows-before ;; there was only one character in the present line ;; (which has now been deleted) (= 1 (length chars-before)) ;; And the last character of the previous row ;; didn't force a new line. (not (char-equal #\Newline (third (second (first rows-before))))) ) (setf input-pos-x (+ (first (second (first rows-before))) (wb:canvas-character-width w (third (second (first rows-before))) :font font))) (setf input-pos-y (first (first rows-before))) ;; drop the last row. (setf character-positions (rest character-positions)) ) ;; ;; tuck updated info away ;; (setf (cdr (assoc vp (input-positions self))) (wb:make-position input-pos-x input-pos-y)) (if (assoc vp (character-positions self)) (setf (cdr (assoc vp (character-positions self))) character-positions) (push (cons vp character-positions) (character-positions self))) ) (T ;; Delete in the middle somewhere. ;; ;; First clear things (let ((line-bottom (- input-pos-y descent 1)) left) (when chars-before ;; Erase rest of the line (setf left (first (first chars-before))) (wb:canvas-draw-filled-rectangle w left r line-bottom (+ line-bottom height) :color back-color) (setf input-pos-x left) ) ;; Now blow out the rest of the viewport (wb:canvas-draw-filled-rectangle w l r b line-bottom :color back-color) ) ;; ;; Update the input-position. ;; (setf chars-before (rest chars-before)) (when (and rows-before (null chars-before) ;; And the last character of the previous row ;; didn't force a new line. (not (char-equal #\Newline (third (second (first rows-before))))) ) (setf input-pos-x (+ (first (second (first rows-before))) (wb:canvas-character-width w (third (second (first rows-before))) :font font))) (setf input-pos-y (first (first rows-before)))) ;; ;; tuck the input-position away ;; (setf (cdr (assoc vp (input-positions self))) (wb:make-position input-pos-x input-pos-y)) ;; ;; Update text string ;; (setf (text-of self) (concatenate 'string (subseq (get-text self) 0 input-index) (subseq (get-text self) (1+ input-index)))) ;; ;; Draw the rest of the string and update things ;; (let ((results NIL)) (setf results (first (draw-&-return-pos-info self vp :string (subseq (get-text self) input-index) :counter input-index ) ) ) ;;(1+ input-index)))) (when results ;; Now tuck the results away on self (let* ((info (rest results)) (input-pos (cdr (assoc :input-position info))) (positions (cdr (assoc :positions info)))) (if (assoc vp (input-positions self)) (setf (cdr (assoc vp (input-positions self))) input-pos) (push (cons vp input-pos) (input-positions self))) ;; ;; Now merge these results with unchanged piece ;; ;; fix the input row ;; (nconc (rest (first (last positions))) chars-before) ;; ;; put all the rows together ;; (nconc positions rows-before) ;; ;; Now tuck the positions away on self ;; (if (assoc vp (character-positions self)) (setf (cdr (assoc vp (character-positions self))) positions) (push (cons vp positions) (character-positions self))) ;; ;; Reset the input position (setf (cdr (assoc vp (input-positions self))) (wb:make-position input-pos-x input-pos-y)) )))) ) ;; Just update, erase, and draw (let ((results NIL)) (cond ((null input-index) ;; At the beginning, just do it. (setf (text-of self) (string char)) (setf results (first (draw-&-return-pos-info self vp))) ) (T ;; Edit in the middle somewhere. ;; ;; Clear things (let ((line-bottom (- input-pos-y descent 1)) left) (when chars-before ;; Erase rest of the line (setf left (+ (first (first chars-before)) (wb:canvas-character-width w (third (first chars-before)) :font font))) (wb:canvas-draw-filled-rectangle w left r line-bottom (+ line-bottom ascent descent) :color back-color) ) ;; Now blow out the rest of the viewport (wb:canvas-draw-filled-rectangle w l r b line-bottom :color back-color) ) ;; ;; Update the input-position. ;; (setf (cdr (assoc vp (input-positions self))) (wb:make-position input-pos-x input-pos-y)) ;; (setf (text-of self) (concatenate 'string (subseq (get-text self) 0 (1+ input-index)) (string char) (subseq (get-text self) (1+ input-index)))) ;; ;; Draw the rest of the string and update things ;; (setf results (first (draw-&-return-pos-info self vp :string (subseq (get-text self) (1+ input-index)) :counter (1+ input-index))))) ) (when results ;; Now tuck the results away on self (let* ((info (rest results)) (positions (cdr (assoc :positions info))) (first-row (first (last positions))) input-char (char-widowed-on-newline? NIL)) (when (null (rest first-row)) ;; our input character went to a new line (setf char-widowed-on-newline? T) (setf positions (butlast positions)) (setf first-row (first (last positions)))) ;; Need to determine the input-position (setf input-char ;; gets the character triple (first ;; gets the last (i.e. first written) character (last ;; without the y value (rest first-row)))) ;; ;; determine the input position ;; (setf input-pos-y (first first-row)) (setf input-pos-x (+ (first input-char) (wb:canvas-character-width w (third input-char) :font font))) (setf input-pos (wb:make-position input-pos-x input-pos-y)) ;; ;; Reset the input position ;; (if (assoc vp (input-positions self)) (setf (cdr (assoc vp (input-positions self))) input-pos) (push (cons vp input-pos) (input-positions self))) ;; ;; Now merge these results with unchanged piece ;; (cond (char-widowed-on-newline? ;; ;; put all the rows together ;; (if input-row (push input-row rows-before)) (nconc positions rows-before)) (T ;; fix the input row ;; (nconc (rest first-row) chars-before) ;; ;; put all the rows together ;; (nconc positions rows-before) ) ) ;; ;; Now tuck the positions away on self ;; (if (assoc vp (character-positions self)) (setf (cdr (assoc vp (character-positions self))) positions) (push (cons vp positions) (character-positions self))) ))))) ) ) ) ;; ;; Redraw the input-mark ;; (draw-input-mark self vp) ) ) ) #| (setf test (make-instance 'editable-text-view :text "Now is the time for all good men to come to the aid of their country.")) (set-text test "Now is the time for all good men to come to the aid of their country.") (setf self test) (setf viewport (make-viewport)) (setf vp (first (viewports-of self))) (setf char wb::*delete-event*) (draw-view test) (inspect test) |#
37,203
Common Lisp
.l
803
27.063512
128
0.429033
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d96a2a0eef278e36812d5c4b8d6cd118ccfd85ebc56bdfa1a23aebb2f0cbb2c6
33,201
[ -1 ]
33,202
text-view.lsp
rwoldford_Quail/source/views/simple-views/text-view.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; text-view.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( text-view number-of-text-lines))) (defclass text-view (label) ((middle-menu :allocation :class :initform nil)) (:default-initargs :justification-menu? nil :orientation-menu? nil)) (defmethod draw-view ((self text-view) &key viewport) (let ((col (draw-style self :color)) (font (draw-style self :font)) (string (get-text self)) (start 0) ) (flet ((read-word (string) (If (> start (length string)) nil (let* ((pos-space (position #\Space string :test #'char= :start start)) (pos-line (position #\Newline string :test #'char= :start start)) result to-newline?) (cond ((and pos-line pos-space) (cond ((< pos-line pos-space) (setq result (subseq string start pos-line)) (setq start (+ 1 pos-line)) (setq to-newline? T)) (T (setq result (subseq string start (+ 1 pos-space))) (setq start (+ 1 pos-space))))) (pos-space (setq result (subseq string start (+ 1 pos-space))) (setq start (+ 1 pos-space))) (pos-line (setq result (subseq string start pos-line)) (setq start (+ 1 pos-line)) (setq to-newline? T)) (T (setq result (subseq string start)) (setq start (+ 1 (length string))))) (cons result to-newline?))))) (with-exposed-viewports self viewport vp (let* ((w (window-of vp)) (leading (wb:canvas-font-leading w :font font)) (descent (wb:canvas-font-descent w :font font)) (ascent (wb:canvas-font-ascent w :font font)) (height (+ leading ascent descent))) (wb:with-pen-color w col (wb:with-canvas-font w font (multiple-value-bind (l r b tp ) (bounds-of vp) (wb:canvas-move-to w l (- tp ascent)) (loop for (word . newline) = (read-word string) until (or (null word) (< (- (wb:canvas-y w) descent) b)) do (when (> (wb:canvas-string-width w word) (- r (wb:canvas-x w))) (wb:canvas-move-to w l (- (wb:canvas-y w) height))) (wb:canvas-draw-string w word) (if newline (wb:canvas-move-to w l (- (wb:canvas-y w) height))) ))))))))) #| (defun number-of-text-lines (text-view width) "Returns the number of lines required to fit the text-view into the given width." (let* ((font (draw-style text-view :font)) (string (get-text text-view)) (n 1) (line-pos 0) (start 0) ) (flet ((read-word (string) (If (> start (length string)) nil (let* ((pos-space (position #\Space string :test #'char= :start start)) (pos-line (position #\Newline string :test #'char= :start start)) (result (cond (pos-line (subseq string start pos-line)) (pos-space (subseq string start (+ 1 pos-space))) (t (subseq string start))))) (setq start (+ 1 (or pos-line pos-space (length string)))) (cons result pos-line))))) (loop for (word . newline) = (read-word string) until (null word) do (when (> (wb:canvas-string-width NIL word :font font) (- width line-pos)) (incf n 1) (setf line-pos 0)) (incf line-pos (wb:canvas-string-width NIL word :font font)) (when newline (incf n 1) (setf line-pos 0)) ) n))) |# (defun number-of-text-lines (text-view width) "Returns the number of lines required to fit the text-view into the given width." (let* ((font (draw-style text-view :font)) (string (get-text text-view)) (n 1) (line-pos 0) (start 0) ) (flet ((read-word (string) (If (> start (length string)) nil (let* ((pos-space (position #\Space string :test #'char= :start start)) (pos-line (position #\Newline string :test #'char= :start start)) (which (cond ((and (numberp pos-space) (numberp pos-line)) (if (< pos-space pos-line) :space :line)) (pos-space :space) (pos-line :line) (T :end))) (result (case which (:line (prog1 (subseq string start pos-line) (setq start (1+ pos-line)))) (:space (prog1 (subseq string start (+ 1 pos-space)) (setq start (1+ pos-space)))) (:end (prog1 (subseq string start) (setq start (1+ (length string)))))))) (cons result (eq which :line)))))) (loop with word-width for (word . newline) = (read-word string) until (null word) do (setq word-width (wb:canvas-string-width NIL word :font font)) (when (> word-width (- width line-pos)) (incf n 1) (setf line-pos 0)) (incf line-pos word-width) (when newline (incf n 1) (setf line-pos 0))) n)))
6,867
Common Lisp
.l
162
27.648148
101
0.438056
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
cb7ed93cebe2944be94c57e89d39c994159b6ab679588ec5ae7ded6f91b86b68
33,202
[ -1 ]
33,203
line.lsp
rwoldford_Quail/source/views/simple-views/line.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; line.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( line line-wmenu compute-line-endpoints oriented-line oriented-line-wmenu set-line-slope set-line-intercept set-line-orientation))) (defclass line (flip-mixin lines-mixin simple-view ) ( (slope :initarg :slope :initform nil :accessor slope-of) (intercept :initarg :intercept :initform nil :accessor intercept-of)) (:default-initargs :menu? t :orientation-menu? nil :documentation "line given by slope and intercept drawn in bounding region") ) (defclass line-menu-mixin () ((middle-menu :allocation :class :initform nil))) (defclass line-wmenu (line-menu-mixin line) ()) (defclass oriented-line (orientation-mixin line ) () (:default-initargs :orientation-menu? nil) (:documentation "a horizontal or vertical drawn at location in bounding region")) (defclass oriented-line-wmenu (line-menu-mixin oriented-line) ((middle-menu :allocation :class :initform nil))) (defgeneric compute-line-endpoints (line ) (:documentation "Use the bounding region to compute the end points of the line" )) (defgeneric set-line-slope (line &key ) (:documentation "sets the slope of line")) (defgeneric set-line-intercept (line &key ) (:documentation "sets the intercept of line")) (defgeneric set-line-orientation (line &key ) (:documentation "sets the orientation to horizontal or vertical")) ;;------------------------------------------------------------------------------ (defmethod initialize-instance :after ((self line) &key orientation menu? intercept) (if (eq (class-name (class-of self)) 'line) (cond ((and orientation menu?) (change-class self 'oriented-line-wmenu) (setf (orientation-of self) orientation) (setf (intercept-of self) intercept) (compute-line-endpoints self)) (menu? (change-class self 'line-wmenu)) (orientation (change-class self 'oriented-line) (setf (orientation-of self) orientation) (setf (intercept-of self) intercept) (compute-line-endpoints self)) (t nil)))) (defmethod set-bounding-region :after ((self line) &key &allow-other-keys) (compute-line-endpoints self)) (defmethod lines-coords-of :before ((self line)) (unless (slot-value self 'lines-coords) (compute-line-endpoints self))) (defmethod compute-line-endpoints ((self line)) (multiple-value-bind (l r b tp) (bounds-of (bounding-region-of self)) (let* ((m (slope-of self)) (c (intercept-of self)) pl pr pb pt) (if (eql m :prompt) (setf (slope-of self) (setf m (wb::prompt-user :result-type t :read-type :eval :prompt-string "Enter new slope")))) (if (eql c :prompt) (setf (intercept-of self) (setf c (wb::prompt-user :result-type t :read-type :eval :prompt-string "Enter new intercept")))) (if (and (numberp m) (not (numberp c))) (setf (intercept-of self) (setf c (/ (+ b tp) 2)))) (setf (lines-coords-of self) (cond ((eql m 0) (list (list l c) (list r c))) ((numberp m) (setq pb (if (<= l (/ (- b c) m) r) (list (/ (- b c) m) b))) (setq pt (if (<= l (/ (- tp c) m) r) (list (/ (- tp c) m) tp))) (setq pl (if (<= b (+ c (* m l)) tp) (list l (+ c (* m l) )))) (setq pr (if (<= b (+ c (* m r)) tp) (list r (+ c (* m r) )))) (remove-if #'null (list pl pb pt pr))) ((numberp c) (list (list c b) (list c tp))) (t (unless (= r l) (setf m (/ (- tp b) (- r l))) (setf (slope-of self) m) (setf (intercept-of self) (- b (* m l)))) (list (list l b) (list r tp))) ))))) (defmethod get-menu-items ((self line-menu-mixin) (slot-name (eql 'middle-menu))) (let ((orientation '(("Horizontal" (set-line-orientation :value :horizontal )) ("Vertical" (set-line-orientation :value :vertical ))))) `( ("-" nil) ( "Slope" (set-line-slope )) ( "Intercept" (set-line-intercept )) ( "Orientation" nil "" :sub-items ,orientation) ))) (defmethod set-line-slope ((self line) &key value (draw? t)) (if (null value) (setf value (wb::prompt-user :result-type t :read-type :eval :prompt-string "Enter new slope"))) (if (not (numberp value)) (set-line-orientation self :value :vertical :draw? t) (let ((class-name (class-name (class-of self)))) (if (and (typep self 'oriented-line) (eq (orientation-of self) :vertical)) (setf (intercept-of self) nil)) (cond ((eq class-name 'oriented-line) (change-class self 'line)) ((eq class-name 'oriented-line-wmenu) (change-class self 'line-wmenu)) (t nil)) (if draw? (erase-view self)) (setf (slope-of self) value) (compute-line-endpoints self) (if draw? (draw-view self))))) (defmethod set-line-intercept ((self line) &key value (draw? t)) (if draw? (erase-view self)) (if (null value) (setf value (wb::prompt-user :result-type 'number :read-type :eval :prompt-string "Enter new intercept"))) (setf (intercept-of self) value) (compute-line-endpoints self) (if draw? (draw-view self))) (defmethod set-line-orientation ((self line) &key value (draw? t)) (let ((class-name (class-name (class-of self)))) (if (or (and (typep self '(not orientation-mixin)) (eq value :vertical)) (and (typep self 'orientation-mixin) (not (eq value (orientation-of self))))) (setf (intercept-of self) nil)) (cond ((eq class-name 'line) (change-class self 'oriented-line)) ((eq class-name 'line-wmenu) (change-class self 'oriented-line-wmenu)) (t nil)) (if draw? (erase-view self)) (setf (orientation-of self) value) (compute-line-endpoints self) (if draw? (draw-view self)))) (defmethod compute-line-endpoints ((self oriented-line) ) (let* ((br (bounding-region-of self)) (xmin (left-of br)) (xmax (right-of br)) (ymin (bottom-of br)) (ymax (top-of br)) (locn (intercept-of self))) (setf (lines-coords-of self) (ecase (orientation-of self) (:horizontal (setf (intercept-of self) (setq locn (cond ((eql locn :prompt) (wb::prompt-user :result-type t :read-type :eval :prompt-string "Enter new y intercept")) ((null locn) (/ (+ ymin ymax) 2)) (t locn)))) (list (list xmin locn) (list xmax locn))) (:vertical (setf (intercept-of self) (setq locn (cond ((eql locn :prompt) (wb::prompt-user :result-type t :read-type :eval :prompt-string "Enter new x intercept")) ((null locn) (/ (+ xmin xmax) 2)) (t locn)))) (list (list locn ymin) (list locn ymax)))))))
8,863
Common Lisp
.l
193
33.497409
92
0.504661
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4820c807435a0a96dfd7f6ba67427feb872b4849f02f9e9ba86c3d5976b1b56c
33,203
[ -1 ]
33,204
line-segment.lsp
rwoldford_Quail/source/views/simple-views/line-segment.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; line-segment.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( line-segment line-segment-wmenu set-endpoints ))) (defclass line-segment (line-segment-mixin simple-view) () (:default-initargs :menu? t :documentation "a line segment between two endpoints")) (defclass line-segment-mixin (flip-mixin lines-mixin) ((lines-coords :initarg :endpoints :initform '((0 0) (1 1)) :accessor lines-coords-of)) ) (defclass line-segment-wmenu (line-segment) ((middle-menu :allocation :class :initform nil)) (:documentation "a line segment between two endpoints,~ with a menu for changing the points")) (defgeneric set-endpoints (line-segment-mixin &key ) (:documentation "sets the end points of line")) (defmethod initialize-instance :before ((self line-segment) &key menu?) (if (and menu? (eq (class-name (class-of self)) 'line-segment)) (change-class self 'line-segment-wmenu))) (defmethod compute-bounding-region ((self line-segment-mixin) ) (let ( left right bottom top) (loop for (x y) in (lines-coords-of self) when x minimize x into minx maximize x into maxx minimize y into miny maximize y into maxy finally (setq left minx right maxx bottom miny top maxy)) (when (= left right) (let ((delta (draw-style self :width))) (cond (delta (decf left delta) (incf right delta)) (T (decf left) (incf right)) ))) (when (= bottom top) (let ((delta (draw-style self :width))) (cond (delta (decf bottom delta) (incf top delta)) (T (decf bottom) (incf top)) )) ) (make-region left right bottom top))) (defmethod get-menu-items ((self line-segment-wmenu) (slot-name (eql 'middle-menu))) '(("-" nil) ( "Endpoints" (set-endpoints)) )) (defmethod set-endpoints ((self line-segment) &key endpoints (draw? t)) (if draw? (erase-view self)) (if (null endpoints) (setf endpoints (list (wb::prompt-user :result-type 'list :read-type :read :prompt-string "Enter first point as list") (wb::prompt-user :result-type 'list :read-type :read :prompt-string "Enter second point as list")))) (setf (lines-coords-of self) endpoints) (if draw? (draw-view self)))
3,403
Common Lisp
.l
93
28.182796
92
0.515549
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d21b3c6b420125e2956b9738abe9ce29af94811eacb5a5c6b3b78724c0305557
33,204
[ -1 ]
33,205
function-view.lsp
rwoldford_Quail/source/views/simple-views/function-view.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; function-view.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( function-view compute-lines-coords set-function set-nlines ))) (defclass function-view (flip-mixin lines-mixin simple-view ) ((middle-menu :allocation :class :initform nil) (domain :initarg :domain :initform :prompt :accessor domain-of) (nlines :initarg :nlines :initform 20 :accessor nlines-of) (function :initform :prompt :initarg :function :accessor function-of :documentation "Function applied ") ) (:documentation "function plotted in bounding region")) (defgeneric set-function (function &key ) (:documentation "sets the function plotted")) (defgeneric set-nlines (function &key ) (:documentation "sets the number of line segments used ")) (defmethod set-bounding-region :after ((self function-view) &key domain &allow-other-keys) (when (or domain (eql (domain-of self) :prompt) ) (setq domain (or domain (domain-of self))) (let ((br (bounding-region-of self))) (when (eql domain :prompt) (setq domain (loop for l in (wb::collect-input (list (cons "from" "0.0") (cons "to" "1.0")) :prompt-text "Enter function domain.") collect (eval (read-from-string (cdr l))))) (setf (domain-of self) domain)) (cond ((interval-p domain) (setf (left-of br) (min-of domain)) (setf (right-of br) (max-of domain))) (t (setf (left-of br) (car domain)) (setf (right-of br) (second domain)))) (let ((lines-coords (compute-lines-coords self))) (loop for (x y) in lines-coords maximize y into top minimize y into bottom finally (setf (bottom-of br) bottom) (setf (top-of br) top)))))) (defmethod lines-coords-of :before ((self function-view)) (unless (slot-value self 'lines-coords) (compute-lines-coords self))) (defmethod compute-lines-coords ((self function-view) ) (let* ((br (bounding-region-of self)) (dom (domain-of self)) (xmin (if dom (first dom) (left-of br))) (xmax (if dom (second dom) (right-of br))) (n (nlines-of self) ) (f (function-of self))) (setq f (get-function f)) (setf (lines-coords-of self) (loop for x in (ordinates-for-fplot (list xmin xmax) (+ n 1)) collect (list x (funcall f x)))))) (defun ordinates-for-fplot(x &optional (n-ordinates 20)) (loop for xi in x minimize xi into minx maximize xi into maxx finally (return (loop with xi = minx with inc-x = (float (/ (- maxx minx) (- n-ordinates 1))) for i from 1 to n-ordinates collect xi do (setq xi (min (+ xi inc-x) maxx)))))) (defmethod get-menu-items ((self function-view) (slot-name (eql 'middle-menu))) '( ("-" nil) ( "Function" (set-function)) ( "# Lines" (set-nlines)) )) (defmethod function-of :before ((self function-view)) (if (eq :prompt (slot-value self 'function)) (let ((f (wb::prompt-user :result-type t :prompt-string "Enter function" :read-type :read))) (setf (slot-value self 'function) (if (and (listp f) (symbolp (car f)) (fboundp (car f))) (eval f) f))))) (defmethod set-function ((self function-view) &key value (draw? t)) (if draw? (erase-view self)) (if (null value) (setf value (wb::prompt-user :result-type t ;;(or 'symbol) :prompt-string "Enter new function" :read-type :read))) (setf (function-of self) value) (compute-lines-coords self) (if draw? (draw-view self))) (defmethod set-nlines ((self function-view) &key value (draw? t)) (if draw? (erase-view self)) (if (null value) (setf value (wb::prompt-user :result-type 'integer :prompt-string "Enter number of segments" :read-type :eval))) (setf (nlines-of self) value) (compute-lines-coords self) (if draw? (draw-view self))) (defmethod coord-string-y ((self function-view)) (let ((f (function-of self)) ) (if (or (eql f 'identity) (eql f #'identity)) (call-next-method) (princ-to-string (function-string f))))) (defmethod make-layer-view ((self function-view) (layer symbol) &rest args) (apply #'view :result-type layer :draw? nil :domain (domain-of self) args)) (defmethod use-x-axis-p ((self function-view)) t) (defmethod use-y-axis-p ((self function-view)) t)
5,852
Common Lisp
.l
134
33.067164
92
0.525657
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
022ff974ae8c2fdc84a3a7214dd2108c273e82eec6d8d71585aa72debc68ed69
33,205
[ -1 ]
33,206
key-input.lsp
rwoldford_Quail/source/views/simple-views/key-input.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; key-input.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views statistical graphics package. ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1996 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) ;;; Now handled in the package def of VIews (import '(wb::handle-key-event)) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(handle-key-event key-input-view))) (defclass key-input-view (view) ((active-input? :initform NIL :initarg :active? :accessor input-mode-p :documentation "Flag to indicate whether the view ~ is accepting input.") (input-positions :initform NIL :accessor input-positions :documentation "The present entry position of the incoming events, by viewport.") ) ) ;;; ;;; Generic methods for starting, stopping, and directing input. ;;; (defgeneric start-input (key-input-view viewport) (:documentation "Initializes view to accept keyboard input.")) (defgeneric stop-input (key-input-view viewport) (:documentation "Stops view from accepting further input.")) (defgeneric refocus-input (key-input-view viewport &optional position) (:documentation "Moves the focus of the input to a new location determined from the ~ given position.")) (defgeneric end-event-input-p (key-input-view event) (:documentation "Test whether the given event should trigger an end to keyboard input.")) ;;; ;;; Interaction begins with the left button ;;; (defmethod left-button-fn ((self key-input-view) &key viewport ) "Left button activates or deactivates the view for keyboard input." ;;(call-next-method) (cond ((and (eq self (selected-view)) (input-mode-p self)) ;; refocus of input (refocus-input self viewport (wb::mouse-position (window-of viewport))) ) ((eq self (selected-view)) (cond ((quail-y-or-n-p "Edit input?") (start-input self viewport)) (T (call-next-method))) ) ((input-mode-p self) (stop-input self viewport) ) (T (call-next-method) (start-input self viewport)))) ;;; end input by handle-key-event when enter is hit. ;;; ;;; The methods ;;; (defmethod start-input ((self key-input-view) viewport) "Does nothing" (declare (ignorable setf viewport)) ;(declare (ignore self viewport)) ; 29JUL2023 ) (defmethod start-input :before ((self key-input-view) viewport) "Ensures that the input mode is turned on before anything else happens." (declare (ignorable viewport)) ;(declare (ignore viewport)) ; 29JUL2023 (setf (input-mode-p self) T)) (defmethod stop-input ((self key-input-view) viewport) "Does nothing" (declare (ignorable setf viewport)) ;(declare (ignore self viewport)) ; 29JUL2023 NIL ) (defmethod stop-input :after ((self key-input-view) viewport) "Ensures that the input mode is turned off after all else is done." (declare (ignorable viewport)) ;(declare (ignore viewport)) ; 29JUL2023 (setf (input-mode-p self) NIL)) (defmethod refocus-input ((self key-input-view) viewport &optional position) "Moves the focus of the input to a new location determined from the ~ given position." (if (assoc viewport (input-positions self)) (setf (cdr (assoc viewport (input-positions self))) position) (push (cons viewport position) (input-positions self)))) (defmethod end-event-input-p ((view key-input-view) (event T)) (declare (ignorable view event)) ;(declare (ignore view event)) ; 29JUL2023 NIL) (defmethod end-event-input-p ((view key-input-view) (event (eql wb:+escape-key-event+))) ;(eql wb:*escape-key-event*))) 23FEB2022 gwb (declare (ignorable view event)) ;(declare (ignore view event)) ;29JUL2023 T) (defmethod handle-key-event ((view key-input-view) event) "Doesn't do much. Just informs user of the events received." (inform-user (format NIL "~&~%Handle-key-event -- View = ~s ~%~20T Event = ~s.~%" view event) ) ) (defmethod handle-key-event ((view view) event) "Hands off to selected view." (let ((selected-view (selected-view))) (unless (eq view selected-view) (handle-key-event selected-view event)))) (defmethod handle-key-event :around ((view key-input-view) event) "Checks to see if input is to be ended." (cond ((end-event-input-p view event) (if (eq (selected-view) view) (select-one view)) (stop-input view NIL) ) ((eq (selected-view) view) (call-next-method)) ) ) #| (setf test (make-instance 'key-input-view)) (draw-view test) (inspect test) |#
5,210
Common Lisp
.l
137
32.532847
116
0.615553
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
7c7a6a05efb0b5d821b2660939a3576822cac35e7a9f6b7e15f8880fbea3e222
33,206
[ -1 ]
33,207
point-symbol.lsp
rwoldford_Quail/source/views/simple-views/point-symbol.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; point-symbol.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( point-symbol label-of point-symbol-type group-point-symbol ))) ;;;---------------------------------------------------------------------------------- (defclass point-symbol (view-with-size linkable-mixin simple-view ) ((middle-menu :allocation :class :initform nil) (style-keys :initform '(:symbol :size :fill? :color) :allocation :class) (label :initarg :label :initform #'identifier-name :documentation "Function which when applied to subject gives a label, or a label")) (:default-initargs :color *default-point-color* :symbol *default-point-symbol* :size *default-point-size* :fill? *default-point-fill?*)) (defclass group-point-symbol (point-symbol) () (:default-initargs :viewed-elements :expand-viewed-object )) (defgeneric label-of (point-symbol)) ;;;---------------------------------------- (defconstant *cos-18* (cos (* pi 0.1)) ) (defconstant *cos-54* (cos (* pi 0.3))) (defconstant *sin-18* (sin (* pi 0.1))) (defconstant *sin-54* (sin (* pi 0.3))) (defmethod label-of ((self point-symbol)) (let ((l (slot-value self 'label))) (if (functionp l) (funcall l (viewed-object-of self)) l))) (defmethod fix-viewports ((self point-symbol) &key viewport ) (let ((size (draw-style self :size))) (loop for vp in (if viewport (list viewport ) (viewports-of self) ) do (set-square-viewport-size vp (+ 2 size)) ))) (defun point-symbol-key (sym) "Returns the symbol key for sym, if one exists." (cond ((member sym *point-symbol-types*) sym) ((stringp sym) :text) ((wb:bitmap-p sym) :bitmap) (t nil))) (defmethod set-draw-style :after ((self point-symbol) (style (eql :size)) new &key) (declare (ignore new)) (fix-viewports self)) (defmethod view-size-of ((self point-symbol)) (draw-style self :size)) (defmethod (setf view-size-of) (new (self point-symbol) ) (set-draw-style self :size new)) (defmethod set-view-size ((self point-symbol) new &rest args) (apply #'set-drawing-style self :size new args) (setf (slot-value self 'view-size) (draw-style self :size))) (defmethod view-size-increment ((self point-symbol)) (if (>= (draw-style self :size) 3) 2 1)) (defmethod draw-view ((self point-symbol) &key viewport) (let ((symbol (draw-style self :symbol)) sym-type) (setf sym-type (or (point-symbol-key symbol) :box)) (with-exposed-viewports self viewport vp (draw-point-symbol self sym-type vp)))) (defmethod draw-point-symbol ((self point-symbol) (symbol (eql :triangle)) viewport) (let ((color (draw-style self :color)) (bw (window-of viewport)) xc yc rad ) (with-point-symbol-center&radius self viewport xc yc rad (if (not (draw-style self :fill?)) (wb:canvas-draw-polygon bw (list (cons (- xc rad) (- yc rad)) (cons xc (+ yc rad)) (cons (+ xc rad) (- yc rad))) :color color :width 1) (wb:canvas-draw-filled-polygon bw (list (cons (- xc rad) (- yc rad)) (cons xc (+ yc rad)) (cons (+ xc rad) (- yc rad))) :color color))))) (defmethod min-size ((symbol t)) 1) (defmethod min-size ((symbol (eql :circle))) 2) (defmethod min-size ((symbol (eql :diamond))) 2) (defmethod min-size ((symbol (eql :triangle))) 2) (defmethod min-size ((symbol (eql :star))) 2) (defmethod min-size ((symbol (eql :poly-star))) 4) (defmethod draw-style ((self point-symbol) (slot-name (eql :symbol)) &key) (let ((shape (call-next-method self slot-name)) (size (draw-style self :size))) (if (< size (min-size shape)) :box shape))) (defmethod draw-point-symbol ((self point-symbol) (symbol (eql :text)) viewport) (let ((color (draw-style self :color)) (bw (window-of viewport)) xc yc rad ) (declare (ignorable xc yc rad)) (with-point-symbol-center&radius self viewport xc yc rad (wb:canvas-draw-string bw (draw-style self :symbol) :region (wb-region viewport) :color color)))) (defmethod draw-point-symbol ((self point-symbol) (symbol (eql :star)) viewport) (let ((bw (window-of viewport)) xc yc rad ) (with-point-symbol-center&radius self viewport xc yc rad (let* ((r*c18 (round (* rad *cos-18*))) (r*s18 (round (* rad *sin-18*))) (r*c54 (round (* rad *cos-54*))) (r*s54 (round (* rad *sin-54*))) (x1 (+ xc r*c18)) (y1 (+ yc r*s18)) (x2 xc) (y2 (+ yc rad)) (x3 (- xc r*c18)) (x4 (- xc r*c54)) (x5 (+ xc r*c54)) (y5 (- yc r*s54))) (wb:with-pen-values bw (draw-style self :color) 1 nil (wb:canvas-draw-line bw xc yc x1 y1) (wb:canvas-draw-line bw xc yc x2 y2) (wb:canvas-draw-line bw xc yc x3 y1) (wb:canvas-draw-line bw xc yc x4 y5) (wb:canvas-draw-line bw xc yc x5 y5)))))) (defmethod draw-point-symbol ((self point-symbol) (symbol (eql :diamond)) viewport) (let ((color (draw-style self :color)) (bw (window-of viewport)) xc yc rad ) (with-point-symbol-center&radius self viewport xc yc rad (if (draw-style self :fill?) (wb:canvas-draw-filled-polygon bw (list (cons (- xc rad) yc) (cons xc (+ yc rad)) (cons (+ xc rad) yc) (cons xc (- yc rad))) :color color) (wb:canvas-draw-polygon bw (list (cons (- xc rad) yc) (cons xc (+ yc rad)) (cons (+ xc rad) yc) (cons xc (- yc rad))) :color color :width 1))))) (defmethod draw-point-symbol ((self point-symbol) (symbol (eql :cross)) viewport) (let ( (bw (window-of viewport)) xc yc rad ) (with-point-symbol-center&radius self viewport xc yc rad (wb:with-pen-values bw (draw-style self :color) 1 nil (wb:canvas-draw-line bw (- xc rad) yc (+ xc rad) yc) (wb:canvas-draw-line bw xc (+ yc rad) xc (- yc rad)))))) (defmethod draw-point-symbol ((self point-symbol) (symbol (eql :circle)) viewport) (let ((color (draw-style self :color)) (bw (window-of viewport)) xc yc rad ) (with-point-symbol-center&radius self viewport xc yc rad (if (draw-style self :fill?) (wb:canvas-draw-filled-circle bw xc yc rad :color color) (wb:canvas-draw-circle bw xc yc rad :color color :width 1))))) (defmethod draw-point-symbol ((self point-symbol) (symbol (eql :bitmap)) viewport) (let (xc yc rad) (declare (ignorable rad)) (with-point-symbol-center&radius self viewport xc yc rad (wb::plot-glyph-at xc yc (draw-style self :symbol) (window-of viewport) )))) (defmethod draw-point-symbol ((self point-symbol) (symbol (eql :box)) viewport) (let ((color (draw-style self :color)) (bw (window-of viewport)) xmin xmax ymin ymax ) (with-point-symbol-bounds self viewport xmin xmax ymin ymax (if (draw-style self :fill?) (wb:canvas-draw-filled-rectangle bw xmin xmax ymin ymax :color color) (wb:canvas-draw-inside-rectangle bw xmin xmax ymin ymax :color color :width 1))))) (defmethod draw-point-symbol ((self point-symbol) (symbol (eql :poly-star)) viewport) (let ((bw (window-of viewport)) (color (draw-style self :color)) xc yc rad ) (with-point-symbol-center&radius self viewport xc yc rad (let* ((r*c18 (round (* rad *cos-18*))) (r*s18 (round (* rad *sin-18*))) (r*c54 (round (* rad *cos-54*))) (r*s54 (round (* rad *sin-54*))) (r (truncate rad 2)) (x1 (+ xc r*c18)) (y1 (+ yc r*s18)) (x2 xc) (y2 (+ yc rad)) (x3 (- xc r*c18)) (y3 y1) (x4 (- xc r*c54)) (y4 (- yc r*s54)) (x5 (+ xc r*c54)) (y5 y4) (u1 (+ xc (truncate r*c54 2))) (v1 (+ yc (truncate r*s54 2))) (u2 (- xc (truncate r*c54 2))) (v2 v1) (u3 (- xc (truncate r*c18 2))) (v3 (- yc (truncate r*s18 2))) (u4 xc) (v4 (- yc r)) (u5 (+ xc (truncate r*c18 2))) (v5 (- yc (truncate r*s18 2))) (p1 (cons x1 y1)) (p2 (cons x2 y2)) (p3 (cons x3 y3)) (p4 (cons x4 y4)) (p5 (cons x5 y5)) (q1 (cons u1 v1)) (q2 (cons u2 v2)) (q3 (cons u3 v3)) (q4 (cons u4 v4)) (q5 (cons u5 v5))) (if (not (draw-style self :fill?)) (wb:canvas-draw-polygon bw (list p1 q1 p2 q2 p3 q3 p4 q4 p5 q5) :color color :width 1) (wb:canvas-draw-filled-polygon bw (list p1 q1 p2 q2 p3 q3 p4 q4 p5 q5) :color color)))))) (defmethod description-string ((self point-symbol)) (let ((name (or (label-of self) (viewed-object-description-string self)))) (if name (format nil "~A viewing ~A" self name) (format nil "~A" self)))) (defmethod distance-to-location ((self point-symbol) viewport location) (let ((locn-c (if (region-p location) (centre-of location) location))) (distance-from viewport locn-c))) (defmethod style-menu-items ((self point-symbol)) (let (( shape-change-list (loop for s in *point-symbol-types* collect `( ,(string-downcase s) (set-drawing-style :symbol ,s))))) `(( "Fill?" (set-drawing-style :fill? :toggle)) ( "Shape" nil "" :sub-items ,shape-change-list) ))) (defmethod highlight-operation ((self point-symbol)) :default ) (defmethod default-left-fn ((self point-symbol) &key viewport &allow-other-keys) (identify-view self :viewport viewport)) (defmethod shift-left-button-fn ((self point-symbol) &key viewport ) ;;(toggle-select-view self) (select-view self) (let ((s (viewed-object-description-string self)) (parent (find-parent self :viewport viewport))) (if parent (setq s (format nil "~A: At ~A" s (subview-location-string parent self) ))) (quail-print s))) (defmethod add-viewport ((self point-symbol) vp pvp &key compute-transform?) (declare (ignore compute-transform?)) (call-next-method self vp pvp :compute-transform? nil))
12,372
Common Lisp
.l
275
33.701818
130
0.522959
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f61fc5a413a7e10f70ff419450d65a44f6dc5b73b0fab2b96c9746f7aa5ff840
33,207
[ -1 ]
33,208
scrollable-view-mixin.lsp
rwoldford_Quail/source/views/scroll/scrollable-view-mixin.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; scrollable-view-mixin.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(scrollable-view-mixin max-view-start view-start check-active-sub-viewports scroll-view move-view-start))) (defclass scrollable-view-mixin () ()) (defgeneric max-view-start (scrollable-view-mixin &key viewport axis) (:documentation "Returns the maximum view start position in viewport along axis.")) (defgeneric view-start (scrollable-view-mixin &key viewport axis) (:documentation "Returns the current view start position in viewport along axis.")) (defgeneric scroll-view (scrollable-view-mixin positions &key axis) (:documentation "Scrolls the view position along axis.")) (defgeneric move-view-start (scrollable-view-mixin &key x y ) (:documentation "Moves the view start to x and y.")) (defmethod compute-sub-viewports ((self scrollable-view-mixin) &optional viewport start) (declare (ignore viewport start)) (quail-error "Please supply a method")) (defmethod compute-sub-viewports :after ((self scrollable-view-mixin) &optional viewport start) (declare (ignore start)) (check-active-sub-viewports self :viewport viewport)) (defmethod reshape-sub-viewports ((self scrollable-view-mixin) viewport &key new-location transform ) (declare (ignore new-location transform)) (map-subviews-to-viewport self viewport)) (defmethod check-active-sub-viewports ((self scrollable-view-mixin) &key viewport) (loop for vp in (if viewport (list viewport) (viewports-of self)) do (loop for s in (subviews-of self) for vp-sub = (select-viewport s vp) do (if (contains-p vp vp-sub) (activate-viewport vp-sub) (deactivate-viewport vp-sub))))) (defmethod move-view-start ((self scrollable-view-mixin) &key x y ) (erase-view self ) (compute-sub-viewports self nil (list x y)) (draw-view self :erase? nil)) (defmethod scroll-view ((self scrollable-view-mixin) positions &key axis) (let ((inc (if (minusp positions) -1 1 ))) ;;(erase-view self ) (loop for vp in (viewports-of self) for start = (view-start self :viewport vp :axis axis) for new-start = (min (max 0 (+ start positions)) (max-view-start self :viewport vp :axis axis)) do (loop repeat (abs (- new-start start) ) do (erase-view self :viewport vp) (compute-sub-viewports self vp (ecase axis (:x (list (incf start inc ) nil)) (:y (list nil (incf start inc )) ))) (draw-view self :erase? nil :viewport vp) ))))
3,680
Common Lisp
.l
74
39.256757
113
0.552086
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
119bacfa661d5fa46080bcf9f2aa479d3da84cb441a00b43e24c9b11aef311ad
33,208
[ -1 ]
33,209
scrolling-display.lsp
rwoldford_Quail/source/views/scroll/scrolling-display.lsp
;;; ;;; scrolling-display.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical ;;; graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(scrolling-display scroller-of scroller-displays-of ))) (defclass scrolling-display (compound-view position-key-mixin) ((right-scroller :initform nil :accessor right-scroller-of) (bottom-scroller :initform nil :accessor bottom-scroller-of) (displays :initform nil :accessor scroller-displays-of) (position-keys :initform '(:gap) :allocation :class)) (:default-initargs :right-scroller t :bottom-scroller t :gap 0)) (defmethod construct-sub-views ((self scrolling-display) &key displays display right-scroller bottom-scroller) (if display (setq displays (list display))) (when displays (let* ((rs (if right-scroller (scroll-bar :min 0 :max 100 :step 1 :orientation :vertical :needle-size 12 :scrolling-views displays :scroll-fn #'move-view-start))) (bs (if bottom-scroller (scroll-bar :min 0 :max 100 :step 1 :orientation :horizontal :needle-size 0.03 :scrolling-views nil :scroll-fn nil))) scrollers) (if rs (push rs scrollers)) (if bs (push bs scrollers)) (setf (subviews-of self) (append displays scrollers)) (setf (scroller-displays-of self) displays) (setf (right-scroller-of self) rs) (setf (bottom-scroller-of self) bs)))) (defmethod compute-sub-viewports ((self scrolling-display) &optional viewport subviews) (declare (ignore subviews)) (loop with s-vp with gap = (getf (default-positions-of self) :gap) for vp in (if viewport (list viewport) (viewports-of self)) do (multiple-value-bind (l r b tp) (bounds-of vp) (let* ((rs (right-scroller-of self)) (bs (bottom-scroller-of self)) (d (scroller-displays-of self)) (scr-left (if rs (- r 15) r)) (scr-bot (if bs (+ b 15) b))) (when rs (setq s-vp (or (select-viewport rs vp) (make-viewport (window-of vp)))) (setf (bounds-of s-vp) (list scr-left r scr-bot tp)) (add-viewport rs s-vp vp)) (when bs (setq s-vp (or (select-viewport bs vp) (make-viewport (window-of vp)))) (setf (bounds-of s-vp) (list l scr-left b scr-bot)) (add-viewport bs s-vp vp)) (incf l gap) (decf tp gap) (decf scr-left gap) (incf scr-bot gap) (loop with reg-l = l for di in d for sv-vp = (or (select-viewport di vp) (make-viewport (window-of vp))) for reg-w = (draw-region-width di) for reg = (make-region reg-l (min scr-left (+ reg-l reg-w)) scr-bot tp ) do (setf (bounds-of sv-vp) reg) (add-viewport di sv-vp vp) (setq reg-l (min scr-left (+ reg-l reg-w ))))) )) ) (defmethod reshape-sub-viewports ((self scrolling-display) viewport &key new-location transform ) (declare (ignore new-location transform)) (map-subviews-to-viewport self viewport)) (defmethod draw-region-width ((self scrolling-display)) (+ (if (right-scroller-of self) 15 0) (* 2 (getf (default-positions-of self) :gap)) (reduce #'+ (mapcar #'draw-region-width (scroller-displays-of self))))) (defmethod draw-region-height ((self scrolling-display)) (+ (if (bottom-scroller-of self) 15 0) (* 2 (getf (default-positions-of self) :gap)) (loop for d in (scroller-displays-of self) maximize (draw-region-height d)))) (defmethod make-draw-viewport ((self scrolling-display) &optional title) (let* ((w (draw-region-width self)) (h (draw-region-height self)) (topi 40) (righti 5) (scroll 15) (win (make-view-window :title title :left (max 0 (- (wb:screen-width) righti scroll w)) :bottom (max 0 (- (wb:screen-height) topi scroll h)) :right (- (wb:screen-width) righti) :top (- (wb:screen-height) topi)))) (make-viewport win)))
5,314
Common Lisp
.l
113
34
121
0.519178
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
8376ea44f6c53765bc177e4c338af30a82243dfd17da84d05745be216197313c
33,209
[ -1 ]
33,210
arrow.lsp
rwoldford_Quail/source/views/scroll/arrow.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; arrow.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical ;;; graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(arrow control-arrow))) ;;;---------------------------------------------------------------------------------- (defclass arrow ( simple-view) ((direction :accessor scroll-direction-of :initarg :direction :initform :up)) ) (defclass control-arrow (control-mixin boxed-view-mixin arrow) ((direction :accessor scroll-direction-of :initarg :direction :initform :up)) ) (defmethod draw-view ((self arrow) &key viewport) (with-exposed-viewports self viewport vp (draw-arrow self (scroll-direction-of self) vp))) (defmethod draw-arrow ((self arrow) (dir (eql :up)) viewport) (multiple-value-bind (l r b tp ) (bounds-of viewport) (let* ((w (window-of viewport)) (cx (round (+ l (* .5 (- r l))))) (cy (round (+ b (* .5 (- tp b))))) (rx (round (* .3 (- r l)))) (ry (round (* .3 (- tp b)))) (ax (round (* .1 (- r l)))) (ay (round (* .3 (- tp b))))) (wb:with-pen-values w (draw-style self :color) 1 nil (wb:canvas-draw-line w (- cx rx) cy (- cx ax) cy) (wb:canvas-draw-line w (+ cx rx) cy (+ cx ax) cy) (wb:canvas-draw-line w (- cx ax) (- cy ay) (+ cx ax) (- cy ay)) (wb:canvas-draw-line w (- cx ax) cy (- cx ax) (- cy ay)) (wb:canvas-draw-line w (+ cx ax) cy (+ cx ax) (- cy ay)) (wb:canvas-draw-line w (- cx rx) cy cx (+ cy ry)) (wb:canvas-draw-line w (+ cx rx) cy cx (+ cy ry)))))) (defmethod draw-arrow ((self arrow) (dir (eql :down)) viewport) (multiple-value-bind (l r b tp ) (bounds-of viewport) (let* ((w (window-of viewport)) (cx (round (+ l (* .5 (- r l))))) (cy (round (+ b (* .5 (- tp b))))) (rx (round (* .3 (- r l)))) (ry (round (* .3 (- b tp)))) (ax (round (* .1 (- r l)))) (ay (round (* .3 (- b tp))))) (wb:with-pen-values w (draw-style self :color) 1 nil (wb:canvas-draw-line w (- cx rx) cy (- cx ax) cy) (wb:canvas-draw-line w (+ cx rx) cy (+ cx ax) cy) (wb:canvas-draw-line w (- cx ax) (- cy ay) (+ cx ax) (- cy ay)) (wb:canvas-draw-line w (- cx ax) cy (- cx ax) (- cy ay)) (wb:canvas-draw-line w (+ cx ax) cy (+ cx ax) (- cy ay)) (wb:canvas-draw-line w (- cx rx) cy cx (+ cy ry)) (wb:canvas-draw-line w (+ cx rx) cy cx (+ cy ry)))))) (defmethod draw-arrow ((self arrow) (dir (eql :left)) viewport) (multiple-value-bind (l r b tp ) (bounds-of viewport) (let* ((w (window-of viewport)) (cx (round (+ l (* .5 (- r l))))) (cy (round (+ b (* .5 (- tp b))))) (rx (round (* .3 (- r l)))) (ry (round (* .3 (- tp b)))) (ax (round (* .3 (- r l)))) (ay (round (* .1 (- tp b))))) (wb:with-pen-values w (draw-style self :color) 1 nil (wb:canvas-draw-line w cx (- cy ry) cx (- cy ay)) (wb:canvas-draw-line w cx (+ cy ry) cx (+ cy ay)) (wb:canvas-draw-line w (+ cx ax) (- cy ay) (+ cx ax) (+ cy ay)) (wb:canvas-draw-line w cx (- cy ay) (+ cx ax) (- cy ay)) (wb:canvas-draw-line w cx (+ cy ay) (+ cx ax) (+ cy ay)) (wb:canvas-draw-line w cx (- cy ry) (- cx rx) cy) (wb:canvas-draw-line w cx (+ cy ry) (- cx rx) cy))))) (defmethod draw-arrow ((self arrow) (dir (eql :right)) viewport) (multiple-value-bind (l r b tp ) (bounds-of viewport) (let* ((w (window-of viewport)) (cx (round (+ l (* .5 (- r l))))) (cy (round (+ b (* .5 (- tp b))))) (rx (round (* .3 (- l r)))) (ry (round (* .3 (- tp b)))) (ax (round (* .3 (- l r)))) (ay (round (* .1 (- tp b))))) (wb:with-pen-values w (draw-style self :color) 1 nil (wb:canvas-draw-line w cx (- cy ry) cx (- cy ay)) (wb:canvas-draw-line w cx (+ cy ry) cx (+ cy ay)) (wb:canvas-draw-line w (+ cx ax) (- cy ay) (+ cx ax) (+ cy ay)) (wb:canvas-draw-line w cx (- cy ay) (+ cx ax) (- cy ay)) (wb:canvas-draw-line w cx (+ cy ay) (+ cx ax) (+ cy ay)) (wb:canvas-draw-line w cx (- cy ry) (- cx rx) cy) (wb:canvas-draw-line w cx (+ cy ry) (- cx rx) cy)))))
5,176
Common Lisp
.l
100
42.06
89
0.452578
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
98577292f2ce24c021f773e6154c096a0a29f64c5c95a84f8ddd6b4764b41f6b
33,210
[ -1 ]
33,211
scroll-bar.lsp
rwoldford_Quail/source/views/scroll/scroll-bar.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; scroll-bar.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical ;;; graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(scroll-bar slider-of scroll-views-to scroll-views ))) ;;;---------------------------------------------------------------------------------- (defclass scroll-bar(control-mixin orientation-mixin compound-view) ((target :initarg :scrolling-views :accessor scrolling-views-of :initform nil) (slider :accessor slider-of :initform nil) (max-arrow :accessor max-arrow-of :initform nil) (min-arrow :accessor min-arrow-of :initform nil) (left-fn :initarg :scroll-fn :accessor scroll-fn-of :initform nil)) (:default-initargs :min 0 :max 1 :step nil :orientation :vertical )) (defmethod construct-sub-views ((self scroll-bar) &rest arg &key max min orientation ) (let* ((s (apply #'needle-slider :needle-size 10 :level (if (eq orientation :vertical) max min) :left-fn #'scroll-views-to :draw? nil arg)) (amax (view :type 'control-arrow :direction (if (eq orientation :vertical) :up :right) :left-fn #'scroll-views :target (list self :max :viewport ))) (amin (view :type 'control-arrow :direction (if (eq orientation :vertical) :down :left) :left-fn #'scroll-views :target (list self :min :viewport)))) (setf (target-of s) `(,self (slider-level-of ,s) :viewport )) (setf (slider-of self) s) (setf (max-arrow-of self) amax) (setf (min-arrow-of self) amin) (setf (subviews-of self) (list s amax amin)))) (defmethod compute-sub-viewports ((self scroll-bar) &optional viewport subviews) (declare (ignore subviews)) (loop with orientation = (orientation-of self) with arrow-wid = 15 for i upfrom 0 for sv in (list (slider-of self) (min-arrow-of self) (max-arrow-of self)) when sv do (loop for vp in (if viewport (list viewport) (viewports-of self)) for sv-vp = (or (select-viewport sv vp) (make-viewport (window-of vp))) do (multiple-value-bind (l r b tp) (bounds-of vp) (setf (bounds-of sv-vp) (if (eq orientation :vertical) (case i (0 (list l r (+ b arrow-wid -1) (- tp arrow-wid -1))) (1 (list l r b (+ b arrow-wid) )) (2 (list l r (- tp arrow-wid) tp))) (case i (0 (list (+ l arrow-wid -1) (- r arrow-wid -1) b tp)) (1 (list l (+ l arrow-wid) b tp )) (2 (list (- r arrow-wid) r b tp)))))) (add-viewport sv sv-vp vp)))) (defmethod reshape-sub-viewports ((self scroll-bar) viewport &key new-location transform ) (declare (ignore new-location transform)) (compute-sub-viewports self viewport)) (defmethod slider-level-to-display-start ((self scroll-bar) display &optional viewport) (setq viewport (or viewport (which-viewport self))) (let* ((slider (slider-of self)) (axis (axis-of-orientation self)) (parent-vp (select-parent-viewport self viewport)) (prop (/ (if (eq axis :y) (- (max-level slider) (slider-level-of slider)) (- (slider-level-of slider) (min-level slider) )) (- (max-level slider) (min-level slider)))) (max-view (max-view-start display :axis axis :viewport (select-viewport display parent-vp)))) (round (* prop max-view) ))) (defmethod scroll-views-to((self scroll-bar) level &key viewport) (declare (ignore viewport)) (let ((lf (scroll-fn-of self)) (slider (slider-of self)) (axis (axis-of-orientation self)) (views (scrolling-views-of self) )) (if (eq level :max) (set-slider-level slider :level (+ (slider-level-of slider) (* 10 (slider-step-of slider)))) (if (eq level :min) (set-slider-level slider :level (- (slider-level-of slider) (* 10 (slider-step-of slider)))))) (when (and views lf) (loop for v in views for level = (slider-level-to-display-start self v ) do (apply lf v (if (eq axis :x) (list :x level) (list :y level))))))) (defmethod scroll-views((self scroll-bar) direction &key viewport) (let ((lf (scroll-fn-of self)) (slider (slider-of self)) (views (scrolling-views-of self) ) (axis (axis-of-orientation self)) (win (window-of viewport)) ) (loop while (and (wb:mouse-down-p) (contains-p viewport (view-position (wb:mouse-position win))) ) do (if (eq direction :max) (set-slider-level slider :level (+ (slider-level-of slider) (* 10 (slider-step-of slider)))) (if (eq direction :min) (set-slider-level slider :level (- (slider-level-of slider) (* 10 (slider-step-of slider)))))) (when (and views lf) (loop for v in views for level = (slider-level-to-display-start self v ) do (apply lf v (if (eq axis :x) (list :x level) (list :y level)))))))) (defmethod legal-subview-p ((self scroll-bar) view) (declare (ignore view)) nil)
6,681
Common Lisp
.l
132
36.674242
121
0.496698
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0bea446be77ec72319084b6711c753bd0f98217cde64f401cf1d96d47ddac777
33,211
[ -1 ]
33,212
scroll-test.lsp
rwoldford_Quail/source/views/scroll/scroll-test.lsp
(in-package :Vw) (setq d (scrolling-display :draw? t :display (case-display-list :data cigs))) (setq r (right-scroller-of d)) (inspect r) (set-drawing-style d :font (wb: (reposition-view d) (scroller-level-of d) (setq s (first (ev d))) (setq v (second (ev d))) (max-display-start v :viewport (vp v)) (display-start-of (car (scroller-displays-of d))) (slider-level-of (car (ev (scroller-of d)))) (draw-view d)
478
Common Lisp
.l
14
28.214286
64
0.623874
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
12b599a752c33e976a4f5116bb9ec89a4e7b07967ed7c7c6651bad3dae23ae1d
33,212
[ -1 ]
33,213
button-control.lsp
rwoldford_Quail/source/views/controls/button-control.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; button-control.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; N. Wiebe 1998-1999 ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(control-mixin control-start control-done))) ;;---------------------------------------------------------------------- (defclass control-mixin ( ) ((target :initarg :target :initform nil :accessor target-of) (control-state :initarg :control-state :initform nil :accessor control-state :documentation "Non NIL when control is here; NIL otherwise.") (control-toggle :initarg :toggle? :initform T :accessor toggle-control :documentation "Non NIL when control is to be toggled after the ~ left function is fired, NIL otherwise.")) (:default-initargs :left-fn nil ) (:documentation "A control-mixin applies its left-fn to targets on a left click")) (defmethod initialize-instance :after ((self control-mixin) &key target) (unless (listp target) (setf (target-of self) (list target)))) (defmethod (setf target-of) :after (target (self control-mixin)) (unless (listp target) (setf (slot-value self 'target) (list target)))) (defmethod control-start ((self control-mixin)) (cond ((viewports-of self) (erase-view self) (setf (control-state self) T) (draw-view self)) (T (setf (control-state self) T)))) (defmethod control-done ((self control-mixin)) (cond ((viewports-of self) (erase-view self) (setf (control-state self) NIL) (draw-view self)) (T (setf (control-state self) NIL))) ) ;; making this before or after would be nicer, but somehow the clicks get confused (defmethod left-button-fn ((self control-mixin) &key viewport ) (let* ((lbf (left-fn-of self)) (args (mapcar #'eval (target-of self))) (vlist (member :viewport args))) (if vlist (push viewport (cdr vlist))) (control-start self) (unwind-protect (if lbf (apply lbf args)) (if (toggle-control self) (control-done self)) ) ) ) (defun other-colour-function (self) (let (temp-colour) (setf temp-colour (wb::prompt-user-for-color)) (set-drawing-style self :button-color temp-colour) )) (defun button-color-menu-items () (declare (special *color-menu-list* *shade-menu-list*)) (loop for c in (if (wb:color-device-p) *color-menu-list* *shade-menu-list*) collect (if (eq (cadr c) :prompt) (list (car c) `(other-colour-function)) (list (car c) `(set-drawing-style :button-color ,(cadr c)))))) ;;; should the following three functions become methods for each button ;;; because of the different slot names for the elliptical button? (defun button-size-function (self h w smaller) (let* ((increment 5) (elliptical-button (eq (type-of self) 'elliptical-button)) (mheight (if elliptical-button (diameter-y self) (max-height self))) (mheight (if (eq mheight :viewport) (height-of (viewport-of self)) mheight)) (height (if h (if smaller ;otherwise larger (- mheight increment) (+ mheight increment)) mheight)) (mwidth (if elliptical-button (diameter-x self) (max-width self))) (mwidth (if (eq mwidth :viewport) (width-of (viewport-of self)) mwidth)) (width (if (eq mwidth :viewport) :viewport (if w (if smaller ;otherwise larger (- mwidth increment) (+ mwidth increment)) mwidth)))) (erase-view self) (cond (elliptical-button ;not larger than the viewport (progn (if (and h (< height (height-of (viewport-of self)))) (setf (diameter-y self) height)) (if (and w (< width (width-of (viewport-of self)))) (setf (diameter-x self) width)))) (T (progn (if (and h (< height (height-of (viewport-of self)))) (setf (max-height self) height)) (if (and w (< width (width-of (viewport-of self)))) (setf (max-width self) width))))) (draw-view self))) (defun button-size-function2 (self h w) (let* ((elliptical-button (eq (type-of self) 'elliptical-button)) (mheight (if elliptical-button (diameter-y self) (max-height self))) (mwidth (if elliptical-button (diameter-x self) (max-width self))) (height (if h (wb::prompt-user :prompt-string (format NIL "Enter height (currently ~s):" (if (eq mheight :viewport) (height-of (viewport-of self)) mheight)) :result-type 'integer :read-type :eval))) (width (if w (wb::prompt-user :prompt-string (format NIL "Enter width (currently ~s): " (if (eq mwidth :viewport) (width-of (viewport-of self)) mwidth)) :result-type 'integer :read-type :eval)))) (erase-view self) (cond (elliptical-button ;not larger than the viewport (progn (if (and h (< height (height-of (viewport-of self)))) (setf (diameter-y self) height)) (if (and w (< width (width-of (viewport-of self)))) (setf (diameter-x self) width)))) (T (progn (if (and h (< height (height-of (viewport-of self)))) (setf (max-height self) height)) (if (and w (< width (width-of (viewport-of self)))) (setf (max-width self) width))))) (draw-view self) )) (defun button-size-function3 (self h w) (erase-view self) (cond ((eq (type-of self) 'elliptical-button) (progn (if h (setf (diameter-y self) (height-of (viewport-of self)))) (if w (setf (diameter-x self) (width-of (viewport-of self)))))) (T (progn (if h (setf (max-height self) (height-of (viewport-of self)))) (if w (setf (max-width self) (width-of (viewport-of self))))))) (draw-view self)) (defun button-size-menu-items () (let* ((button-size-menu-subitems1 `(("smaller" (button-size-function T T T)) ("larger" (button-size-function T T NIL)) ("prompt" (button-size-function2 T T)) ("viewport" (button-size-function3 T T)) )) (button-size-menu-subitems2 `(("smaller" (button-size-function NIL T T)) ("larger" (button-size-function NIL T NIL)) ("prompt" (button-size-function2 NIL T)) ("viewport" (button-size-function3 NIL T)) )) (button-size-menu-subitems3 `(("smaller" (button-size-function T NIL T)) ("larger" (button-size-function T NIL NIL)) ("prompt" (button-size-function2 T NIL)) ("viewport" (button-size-function3 T NIL)) ))) `(("Size" nil "" :sub-items ,button-size-menu-subitems1) ("Width" nil "" :sub-items ,button-size-menu-subitems2) ("Height" nil "" :sub-items ,button-size-menu-subitems3)))) ;does control-mixin have any subclasses other than button subclasses? (defmethod style-menu-items :around ((self control-mixin)) (let ((result (call-next-method))) (add-menu-items self `(( "Button Color" nil "" :sub-items ,(button-color-menu-items)) ( "Button Size" nil "" :sub-items ,(button-size-menu-items))) result) )) #| (defmethod draw-view :before ((self button-color-mixin) &key viewport) (if (has-draw-style-p self :button-color) (let ((bg-color (draw-style self :button-color))) (with-exposed-viewports self viewport vp (unless (wb:eq-colors bg-color (wb:canvas-background-color (window-of vp))) (fill-viewport vp :color bg-color) ))))) |# #| (defmethod ctrl-left-button-fn ((self control-mixin) &key viewport ) (declare (ignore viewport ))) (defmethod ctrl-middle-button-fn ((self control-mixin) &key viewport ) (declare (ignore viewport ))) (defmethod ctrl-right-button-fn ((self control-mixin) &key viewport) (declare (ignore viewport ))) (defmethod shift-left-button-fn ((self control-mixin) &key viewport ) (declare (ignore viewport))) (defmethod shift-middle-button-fn ((self control-button) &key viewport ) (declare (ignore viewport ))) (defmethod shift-right-button-fn ((self control-button) &key viewport ) (declare (ignore viewport ))) |#
10,211
Common Lisp
.l
224
33.526786
110
0.522267
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0d96169ad065817d7d6f8f0ea7131b24b38196db9e5bd0552bb62263aac4e977
33,213
[ -1 ]
33,214
double-slider.lsp
rwoldford_Quail/source/views/controls/double-slider.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; double-slider.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical ;;; graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1994 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(double-slider slider-low-level-of slider-high-level-of double-bar-slider double-needle-slider))) ;;;---------------------------------------------------------------------------------- (defclass double-slider (slider) ((low-level :accessor slider-low-level-of :initarg :low-level :initform nil ) (high-level :accessor slider-high-level-of :initarg :high-level :initform nil ))) (defclass double-needle-slider (double-slider) ((style-keys :initform '(:color :needle-size :box-color) :allocation :class)) (:default-initargs :needle-size 10 )) (defclass double-bar-slider (double-slider) ((low-color :accessor slider-low-color-of :initarg :low-color :initform nil ) (high-color :accessor slider-high-color-of :initarg :high-color :initform nil )) (:default-initargs :pretty? nil)) (defmethod initialize-instance :after ((self double-slider) &key) (if (null (slider-high-level-of self)) (setf (slider-high-level-of self) (+ (* 0.25 (min-level self)) (* 0.75 (max-level self))))) (if (null (slider-low-level-of self)) (setf (slider-low-level-of self) (+ (* 0.75 (min-level self)) (* 0.25 (max-level self)))))) (defmethod get-map-portion ((self double-needle-slider) viewport) (let ((adjust-vp (copy-region viewport)) (ns (truncate (draw-style self :needle-size) 2))) (ecase (orientation-of self) (:horizontal (incf (left-of adjust-vp) ns) (decf (right-of adjust-vp) ns)) (:vertical (incf (bottom-of adjust-vp) ns) (decf (top-of adjust-vp) ns))) adjust-vp)) (defmethod draw-view ((self double-needle-slider) &key viewport) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (lo (slider-low-level-of self)) (hi (slider-high-level-of self)) (ns (truncate (draw-style self :needle-size) 2))) (loop for level in (list lo hi) do (if (eql (orientation-of self) :horizontal) (setq r (round (+ ns (x-shift map) (* level (x-scale map)))) l (round (+ (- ns) (x-shift map) (* level (x-scale map))))) (setq tp (round (+ ns (y-shift map) (* level (y-scale map)))) b (round (+ (- ns) (y-shift map) (* level (y-scale map)))))) (wb:canvas-draw-filled-rectangle (window-of vp) l r b tp :color (draw-style self :color))))))) (defmethod erase-slider ((self double-needle-slider) &key viewport) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (lo (slider-low-level-of self)) (hi (slider-high-level-of self)) (ns (truncate (draw-style self :needle-size) 2))) (loop for level in (list lo hi) do (if (eql (orientation-of self) :horizontal) (setq r (round (+ ns (x-shift map) (* level (x-scale map)))) l (round (+ (- ns) (x-shift map) (* level (x-scale map))))) (setq tp (round (+ ns (y-shift map) (* level (y-scale map)))) b (round (+ (- ns) (y-shift map) (* level (y-scale map)))))) (wb:canvas-clear (window-of vp) :canvas-left l :canvas-bottom b :width (+ 1 (- r l)) :height (+ 1 (- tp b)))))))) (defmethod set-slider-level ((self double-slider) &key low-level high-level viewport position) (if (and (null low-level) (null high-level) position) (let* ((pos-local (apply-transform (invert-transform (select-map-to-viewport self viewport) ) position)) (new (if (eql (orientation-of self) :horizontal) (2d-position-x pos-local) (2d-position-y pos-local)))) (if (< (abs (- new (slider-low-level-of self))) (abs (- new (slider-high-level-of self)))) (setq low-level new high-level (slider-high-level-of self) ) (setq high-level new low-level (slider-low-level-of self) )))) (if (slider-step-of self) (setf low-level (* (slider-step-of self) (round low-level (slider-step-of self))) high-level (* (slider-step-of self) (round high-level (slider-step-of self))))) (setf low-level (max (min-level self) (min low-level (max-level self))) high-level (max (min-level self) (min high-level (max-level self)))) (unless (and (= low-level (slider-low-level-of self)) (= high-level (slider-high-level-of self))) (erase-slider self :low-level low-level :high-level high-level) (setf (slider-low-level-of self) low-level) (setf (slider-high-level-of self) high-level) (draw-view self))) (defmethod draw-view ((self double-bar-slider) &key viewport) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (low (slider-low-level-of self)) (l1 l) (r1 r) (b1 b) (tp1 tp) (hi (slider-high-level-of self))) (if (eql (orientation-of self) :horizontal) (setq l1 (round (+ (x-shift map) (* low (x-scale map)))) r1 (round (+ (x-shift map) (* hi (x-scale map)))) ) (setq b1 (round (+ (y-shift map) (* low (y-scale map))) ) tp1 (round (+ (y-shift map) (* hi (y-scale map))))) ) (wb:canvas-draw-filled-rectangle (window-of vp) l l1 b tp :color (slider-low-color-of self)) (wb:canvas-draw-filled-rectangle (window-of vp) r1 r b tp :color (slider-high-color-of self)) (wb:canvas-draw-filled-rectangle (window-of vp) l1 r1 b1 tp1 :color (draw-style self :color)))))) (defmethod erase-slider ((self double-bar-slider) &key viewport ) (erase-view self :viewport viewport))
6,992
Common Lisp
.l
133
42.263158
122
0.541178
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
df77730be26c502534d51730ce3d1359304c05aee59a5bc3b6cc3c3467efd282
33,214
[ -1 ]
33,215
control-button.lsp
rwoldford_Quail/source/views/controls/control-button.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; control-button.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; N. Wiebe 1998 ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(control-button))) ;;---------------------------------------------------------------------- (defvar *control-button-text-color* *black-color*) ;originally defvar-ed in views/views-general/special-vars.lsp .. therefore ;; 18SEP 2023 (setf *control-button-text-color* *gray-color*) ;(defvar *control-button-color* *gray-color*) (defclass control-button (control-mixin label) ((style-keys :initform '(:button-color :font :color) :allocation :class) (button-height :initform 2 :initarg :button-height :accessor button-height :documentation "Perceived 3d height of the button above ~ the screen in pixels.") (button-color-menu? :initarg :button-color-menu? :initform T :accessor button-color-menu-p) (button-size-menu? :initarg :button-size-menu? :initform T :accessor button-size-menu-p) (max-height :initform :viewport :initarg :max-height :accessor max-height :documentation "Maximum height of the button") (max-width :initform :viewport :initarg :max-width :accessor max-width :documentation "Maximum width of the button") ) (:default-initargs :font wb:*small-graphics-font* :color *control-button-text-color* :button-color *control-button-color* )) (defmethod selected-p ((self control-button) viewport location) ;; is view selected with mouse at location? ;; default looks to see if location is in viewport (let* ((width (width-of viewport)) (height (height-of viewport)) (mwidth (max-width self)) (mwidth (if (eq mwidth :viewport) width mwidth)) (mheight (max-height self)) (mheight (if (eq mheight :viewport) height mheight)) (p (min (/ width mwidth) (/ height mheight) 1)) (x-centre (+ (left-of viewport) (/ width 2))) (y-centre (+ (bottom-of viewport) (/ height 2))) (width (* p mwidth)) (half-width (/ width 2)) (height (* p mheight)) (half-height (/ height 2)) (left (round (- x-centre half-width))) (right (round (+ x-centre half-width))) (top (round (+ y-centre half-height))) (bottom (round (- y-centre half-height))) (x 0) ;; 14MAR2022 gwb (y 0) ;; 14MAR2022 gwb ) (if (not (numberp (elt location 0))) (setf x (elt location 1) y (elt location 2)) ;; sbcl requires x and y to be initialised before being used 14MAR2022 gwb (setf x (elt location 0) y (elt location 1)) ) (and (active-viewport-p viewport) (if (2d-position-p location) (let ((x (2d-position-x location)) (y (2d-position-y location))) (and (>= x left) (<= x right) (>= y bottom) (<= y top))) (if (region-p location) (multiple-value-bind (l r b tp) (bounds-of location) (and (>= l left) (<= r right) (>= b bottom) (<= tp top)))))))) (defmethod draw-view ((self control-button) &key viewport) (let ((just (justification-of self)) (dir (orientation-of self)) (font (draw-style self :font)) (col (draw-style self :color)) (string (get-text self)) (button-color (draw-style self :button-color))) (unless (wb:canvas-font-p font) (setq font (let ((vp (car (viewports-of self)))) (wb:canvas-make-font :size (max 7 (min 16 (truncate (* 0.5 (min (width-of vp) (height-of vp))))))))) (set-draw-style self :font font)) (if (null dir) (let ((vp (car (viewports-of self)))) (setf (orientation-of self) (setq dir (if (> (height-of vp) (width-of vp)) :vertical :horizontal))))) (with-exposed-viewports self viewport vp (let* ((canvas (window-of vp)) (width (width-of vp)) (height (height-of vp)) (mwidth (max-width self)) (mwidth (if (eq mwidth :viewport) width mwidth)) (mheight (max-height self)) (mheight (if (eq mheight :viewport) height mheight)) (p (min (/ width mwidth) (/ height mheight) 1)) (x-centre (+ (left-of vp) (/ width 2))) (y-centre (+ (bottom-of vp) (/ height 2))) (width (* p mwidth)) (half-width (/ width 2)) (height (* p mheight)) (half-height (/ height 2)) (left (round (- x-centre half-width))) (right (round (+ x-centre half-width))) (top (round (+ y-centre half-height))) (bottom (round (- y-centre half-height))) left-top-colour bottom-right-colour (button-height (truncate (abs (button-height self)))) (half-button-height (truncate button-height 2)) ) (cond ((control-state self) (setf left-top-colour (wb::darken button-color)) (setf bottom-right-colour (wb::lighten button-color)) ) (T (setf left-top-colour (wb::lighten button-color)) (setf bottom-right-colour (wb::darken button-color)) ) ) (wb:canvas-draw-filled-rectangle canvas left right bottom top :color button-color) (wb:canvas-draw-line canvas right bottom right top :width button-height :color bottom-right-colour) (wb:canvas-draw-line canvas left bottom right bottom :width button-height :color bottom-right-colour) (wb:canvas-draw-line canvas left bottom left top :width button-height :color left-top-colour) (wb:canvas-draw-line canvas left top right top :width button-height :color left-top-colour) ; (wb::canvas-draw-rectangle canvas (- left button-height) (+ right button-height 1) ; (- bottom button-height 1) (+ top button-height) ; :width 1 :color wb::*black-colour*) (wb:canvas-draw-line canvas (+ button-height right) (- bottom button-height) (+ button-height right) (+ half-button-height top) :width 1 :color wb::*black-colour*) (wb:canvas-draw-line canvas (- left half-button-height) (- bottom button-height) (+ button-height right) (- bottom button-height) :width 1 :color wb::*black-colour*) (wb:canvas-draw-line canvas (- left half-button-height) (- bottom button-height) (- left half-button-height) (+ half-button-height top) :width 1 :color wb::*black-colour*) (wb:canvas-draw-line canvas (- left half-button-height) (+ half-button-height top) (+ button-height right) (+ half-button-height top) :width 1 :color wb::*black-colour*) (wb:canvas-draw-string canvas string :left (+ left button-height) :width (- width button-height button-height) :bottom (+ bottom button-height) :height (- height button-height button-height) :font font :orientation dir :clip? t :justification just :color col) ) )))
8,945
Common Lisp
.l
190
33.8
144
0.4958
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
877725e27261cd30aa569534846cd1936aaa1bc883a5edd1dccaf81424db9899
33,215
[ -1 ]
33,216
rounded-button.lsp
rwoldford_Quail/source/views/controls/rounded-button.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; rounded-button.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; N. Wiebe 1998 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(rounded-button))) ;;---------------------------------------------------------------------- (defvar *rounded-button-text-color* *black-color*) (defvar *rounded-button-color* *gray-color*) (defclass rounded-button (control-mixin label) ((style-keys :initform '(:button-color :font :color) :allocation :class) (button-height :initform 2 :initarg :button-height :accessor button-height :documentation "Perceived 3d height of the button above ~ the screen in pixels.") (max-height :initform 30 :initarg :max-height :accessor max-height :documentation "Maximum height of the button") (max-width :initform 80 :initarg :max-width :accessor max-width :documentation "Maximum width of the button")) (:default-initargs :font wb:*small-graphics-font* :color *rounded-button-text-color* :button-color *rounded-button-color* )) (defmethod selected-p ((self rounded-button) viewport location) ;; is view selected with mouse at location? ;; default looks to see if location is in viewport (let* ((width (width-of viewport)) (height (height-of viewport)) (mwidth (max-width self)) (mwidth (if (eq mwidth :viewport) width mwidth)) (mheight (max-height self)) (mheight (if (eq mheight :viewport) height mheight)) (p (min (/ width mwidth) (/ height mheight) 1)) (x-centre (+ (left-of viewport) (/ width 2))) (y-centre (+ (bottom-of viewport) (/ height 2))) (width (* p mwidth)) (half-width (/ width 2)) (height (* p mheight)) (half-height (/ height 2)) (left (round (- x-centre half-width))) (right (round (+ x-centre half-width))) (top (round (+ y-centre half-height))) (bottom (round (- y-centre half-height))) (button-height (truncate (abs (button-height self)))) (curve (* 2 button-height)) (x (elt location 0)) (y (elt location 1))) (and (active-viewport-p viewport) (or (and (>= x (+ left curve)) (<= x (- right curve)) (>= y bottom) (<= y top)) (and (>= x left) (< x (+ left curve)) (>= y (+ (* -1 (- x left)) bottom curve)) (<= y (- (+ (- x left) top) curve))) (and (<= x right) (> x (- right curve)) (>= y (+ (- x right) bottom curve)) (<= y (- (+ (* -1 (- x right)) top) curve))))))) (defmethod draw-view ((self rounded-button) &key viewport) (let ((just (vw::justification-of self)) (dir (orientation-of self)) (font (draw-style self :font)) (col (draw-style self :color)) (string (get-text self)) (button-color (draw-style self :button-color))) (unless (wb:canvas-font-p font) (setq font (let ((vp (car (viewports-of self)))) (wb:canvas-make-font :size (max 7 (min 16 (truncate (* 0.5 (min (width-of vp) (height-of vp))))))))) (set-draw-style self :font font)) (if (null dir) (let ((vp (car (viewports-of self)))) (setf (orientation-of self) (setq dir (if (> (height-of vp) (width-of vp)) :vertical :horizontal))))) (with-exposed-viewports self viewport vp (let* ((canvas (window-of vp)) (width (width-of vp)) (height (height-of vp)) (mwidth (max-width self)) (mwidth (if (eq mwidth :viewport) width mwidth)) (mheight (max-height self)) (mheight (if (eq mheight :viewport) height mheight)) (p (min (/ width mwidth) (/ height mheight) 1)) (x-centre (+ (left-of vp) (/ width 2))) (y-centre (+ (bottom-of vp) (/ height 2))) (width (* p mwidth)) (half-width (/ width 2)) (height (* p mheight)) (half-height (/ height 2)) (left (round (- x-centre half-width))) (right (round (+ x-centre half-width))) (top (round (+ y-centre half-height))) (bottom (round (- y-centre half-height))) (button-height (truncate (abs (button-height self)))) (half-button-height (truncate button-height 2)) (curve (* 2 button-height)) (list-of-points (list (cons left (+ bottom curve)) (cons left (- top curve)) (cons (+ left curve) top) (cons (- right curve) top) (cons right (- top curve)) (cons right (+ bottom curve)) (cons (- right curve) bottom) (cons (+ left curve) bottom) (cons left (+ bottom curve)) )) left-top-colour bottom-right-colour ) (cond ((vw::control-state self) (setf left-top-colour (wb::darken button-color)) (setf bottom-right-colour (wb::lighten button-color)) ) (T (setf left-top-colour (wb::lighten button-color)) (setf bottom-right-colour (wb::darken button-color)) ) ) (wb:canvas-draw-filled-polygon canvas list-of-points :color button-color) (wb:canvas-draw-line canvas left (+ bottom curve) left (- top curve) :width button-height :color left-top-colour) (wb:canvas-draw-line canvas left (- top curve) (+ left curve) top :width button-height :color left-top-colour) (wb:canvas-draw-line canvas (+ left curve) top (- right curve) top :width button-height :color left-top-colour) (wb:canvas-draw-line canvas (- right curve) top right (- top curve) :width button-height :color (wb::lighten button-color :factor .1)) (wb:canvas-draw-line canvas right (- top curve) right (+ bottom curve) :width button-height :color bottom-right-colour) (wb:canvas-draw-line canvas right (+ bottom curve) (- right curve) bottom :width button-height :color bottom-right-colour) (wb:canvas-draw-line canvas (- right curve) bottom (+ left curve) bottom :width button-height :color bottom-right-colour) (wb:canvas-draw-line canvas (+ left curve) bottom left (+ bottom curve) :width button-height :color (wb::lighten button-color :factor .1)) ;;outline (wb:canvas-draw-line canvas (- left half-button-height) (- (+ bottom curve) button-height) (- left half-button-height) (+ (- top curve) half-button-height) :width 1 :color wb::*black-colour*) (wb:canvas-draw-line canvas (- left half-button-height) (+ (- top curve) half-button-height) (- (+ left curve) button-height) (+ half-button-height top) :width 1 :color wb::*black-colour*) (wb:canvas-draw-line canvas (- (+ left curve) button-height) (+ half-button-height top) (+ button-height (- right curve)) (+ half-button-height top) :width 1 :color wb::*black-colour*) (wb:canvas-draw-line canvas (+ button-height (- right curve)) (+ half-button-height top) (+ button-height right) (+ (- top curve) half-button-height) :width 1 :color wb::*black-colour*) (wb:canvas-draw-line canvas (+ button-height right) (+ (- top curve) half-button-height) (+ button-height right) (- (+ bottom curve) button-height) :width 1 :color wb::*black-colour*) (wb:canvas-draw-line canvas (+ button-height right) (- (+ bottom curve) button-height) (+ button-height (- right curve)) (- bottom button-height) :width 1 :color wb::*black-colour*) (wb:canvas-draw-line canvas (+ button-height (- right curve)) (- bottom button-height) (- (+ left curve) half-button-height) (- bottom button-height) :width 1 :color wb::*black-colour*) (wb:canvas-draw-line canvas (- (+ left curve) half-button-height) (- bottom button-height) (- left half-button-height) (- (+ bottom curve) button-height) :width 1 :color wb::*black-colour*) (wb:canvas-draw-string canvas string :left (+ left button-height) :width (- width button-height button-height) :bottom (+ bottom button-height) :height (- height button-height button-height) :font font :orientation dir :clip? t :justification just :color col) ) )))
10,565
Common Lisp
.l
206
35.718447
164
0.478155
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
956af796bade53e5ec83983d45dac4477b215f28885fe046c60b48dd66eacb83
33,216
[ -1 ]
33,217
prompt-widget.lsp
rwoldford_Quail/source/views/controls/prompt-widget.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; prompt-widget.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :vw) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(color-chip logical-widget logical-value-of check-box ballot-box radio-button ))) (defclass color-chip (simple-view) ((style-keys :initform '(:color) :allocation :class) ) (:default-initargs :color wb:*black-colour* :left-fn nil ) (:documentation "A simple view that produces a rectangular color ~ chip the same size as its viewport.")) (defmethod draw-view ((self color-chip) &key viewport) (with-exposed-viewports self viewport vp (let ((bw (window-of vp)) (color (draw-style self :color))) (multiple-value-bind (left right bottom top) (bounds-of vp) (wb::canvas-draw-filled-rectangle bw left right bottom top :color color) )))) (defmethod get-menu-items ((self color-chip) (slot-name (eql 'left-menu))) (color-menu-items)) (defclass logical-widget (simple-view ) ((style-keys :initform '(:color) :allocation :class)) (:default-initargs :viewed-object NIL) (:documentation "A simple view that records and displays a logical value.")) (defgeneric logical-value-of (logical-widget) (:documentation "Returns the logical value of the widget.")) (defmethod logical-value-of ((thing logical-widget)) (viewed-object-of thing)) (defmethod (setf logical-value-of) (new-value (thing logical-widget)) (setf (viewed-object-of thing) new-value)) (defmethod draw-view ((self logical-widget) &key viewport) (if (viewed-object-of self) (with-exposed-viewports self viewport vp (let ((bw (window-of vp)) (color (draw-style self :color))) (multiple-value-bind (left right bottom top) (bounds-of vp) (wb::canvas-draw-filled-rectangle bw left right bottom top :color color) ))) (with-exposed-viewports self viewport vp (let ((bw (window-of vp)) (color (draw-style self :color))) (multiple-value-bind (left right bottom top) (bounds-of vp) (wb::canvas-draw-rectangle bw left right bottom top :color color :width 2) )))) ) ;;; Change button behaviours. (defmethod default-left-fn ((self logical-widget) &key viewport ) (setf (viewed-object-of self) (not (viewed-object-of self))) (draw-view self :viewport viewport :erase? T)) (defmethod right-button-fn ((self logical-widget) &key viewport) (declare (ignorable self viewport)) ;(declare (ignore self viewport)) ; 29JUL2023 ()) (defmethod shift-left-button-fn ((self logical-widget) &key viewport ) (declare (ignorable self viewport)) ;(declare (ignore self viewport)) ; 29JUL2023 ()) (defmethod shift-middle-button-fn ((self logical-widget) &key viewport) (declare (ignorable self viewport)) ;(declare (ignore self viewport)) ; 29JUL2023 ()) (defmethod shift-right-button-fn ((self logical-widget) &key viewport) (declare (ignorable self viewport)) ;(declare (ignore self viewport)) ; 29JUL2023 ()) ;;; Some special classes. (defclass check-box (logical-widget) () (:documentation "A simple view that records and displays a logical value via a check mark.")) (defmethod draw-view ((self check-box) &key viewport) (if (viewed-object-of self) (with-exposed-viewports self viewport vp (let ((bw (window-of vp)) (color (draw-style self :color))) (multiple-value-bind (left right bottom top) (bounds-of vp) (wb::canvas-draw-rectangle bw left right bottom top :color color :width 2) (wb::canvas-draw-line bw (+ left 4) (truncate (+ bottom top) 2) (+ left (truncate (- right left) 3)) (+ bottom 4) :width 2 :color color) (wb::canvas-draw-line bw (+ left (truncate (- right left) 3)) (+ bottom 4) (- right 4) (- top 4) :width 2 :color color) ))) (with-exposed-viewports self viewport vp (let ((bw (window-of vp)) (color (draw-style self :color))) (multiple-value-bind (left right bottom top) (bounds-of vp) (wb::canvas-draw-rectangle bw left right bottom top :color color :width 2) )))) ) (defclass ballot-box (logical-widget) () (:documentation "A simple view that records and displays a logical value via an X.")) (defmethod draw-view ((self ballot-box) &key viewport) (if (viewed-object-of self) (with-exposed-viewports self viewport vp (let ((bw (window-of vp)) (color (draw-style self :color))) (multiple-value-bind (left right bottom top) (bounds-of vp) (wb::canvas-draw-rectangle bw left right bottom top :color color :width 2) (wb::canvas-draw-line bw left top right bottom :color color :width 2) (wb::canvas-draw-line bw left bottom right top :color color :width 2) ))) (with-exposed-viewports self viewport vp (let ((bw (window-of vp)) (color (draw-style self :color))) (multiple-value-bind (left right bottom top) (bounds-of vp) (wb::canvas-draw-rectangle bw left right bottom top :color color :width 2) )))) ) (defclass radio-button (logical-widget) () (:documentation "A simple view that records and displays a logical value via a circle.")) (defmethod draw-view ((self radio-button) &key viewport) (with-exposed-viewports self viewport vp (let* ((bw (window-of vp)) (color (draw-style self :color)) (centre (centre-of vp)) (x (2d-position-x centre)) (y (2d-position-y centre)) (radius (truncate (min (height-of vp) (width-of vp)) 2))) (wb::canvas-draw-circle bw x y radius :color color :width 2) (if (viewed-object-of self) (wb::canvas-draw-filled-circle bw x y (max 2 (truncate (* .4 radius))) :color color) )) ) ) #| (view-layout :subviews (list (make-instance 'ballot-box) (make-instance 'check-box) (make-instance 'radio-button) (make-instance 'color-chip)) :positions '((100 140 100 140) (150 190 100 140) (100 140 150 190) (150 190 150 190)) :bounding-region (make-region 0 300 0 300) :draw? T) |#
7,619
Common Lisp
.l
163
36.411043
146
0.563419
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
043e864e3931ffbf6408a5d237ee2a13698d9f4070435668a3aef0d6f353a98c
33,217
[ -1 ]
33,218
range-slider.lsp
rwoldford_Quail/source/views/controls/range-slider.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; range-slider.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: N. Wiebe 1999 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(range-slider-mixin hue-range-slider lightness-range-slider))) ;;;---------------------------------------------------------------------------------- (defclass range-slider-mixin (double-bar-slider) ((saturation :accessor slider-saturation-of :initform 1 :initarg :saturation :documentation "Value should be between 0 and 1.") (color-model :accessor color-model-of :initform :triangle :initarg :color-model :documentation "Model which transforms lhs to rgb.") (flip-range? :accessor flip-range? :initform nil :initarg :flip-range? :documentation "Flips the range of values.") ) (:documentation "Superclass to sliders that show hue and lightness ranges.") ) (defclass hue-range-slider (range-slider-mixin) ((lightness :accessor slider-lightness-of :initform 0.5 :initarg :lightness :documentation "Value should be between 0 and 1.") ) (:documentation "A slider showing a range of hue.~ Hue values are always 'mod'-ed 360 so min- and ~ max-levels should be something appropriate.") (:default-initargs :min 0 :max 720)) (defclass lightness-range-slider (range-slider-mixin) ((hue :accessor slider-hue-of :initform nil :initarg :hue :documentation "Will be 'mod'-ed by 360.") ) (:documentation "A slider showing a range of lightness.~ Lightness values actually range between 0 and 1 ~ but for picture density, choose a large max-level.") (:default-initargs :min 0 :max 720)) (defmethod draw-view ((self hue-range-slider) &key viewport) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (low (slider-low-level-of self)) (hi (slider-high-level-of self)) (flip (flip-range? self))) (case (orientation-of self) (:horizontal (let* ((begin low) (end hi) x-pos) (loop for x from begin to end do (setf x-pos (truncate (+ (x-shift map) (* x (x-scale map))))) (wb:canvas-draw-line (window-of vp) x-pos b x-pos tp :color (apply #'wb::make-color (wb:lhs_to_rgb (slider-lightness-of self) (if flip (- 359 (mod x 360)) (mod x 360)) (slider-saturation-of self) :model (color-model-of self)) )) ) ) ) (:vertical (let* ((begin low) (end hi) y-pos) (loop for y from begin to end do (setf y-pos (truncate (+ (y-shift map) (* y (y-scale map))))) (wb:canvas-draw-line (window-of vp) l y-pos r y-pos :color (apply #'wb::make-color (wb:lhs_to_rgb (slider-lightness-of self) (if flip (- 359 (mod y 360)) (mod y 360)) (slider-saturation-of self) :model (color-model-of self)) )) )))) )))) (defmethod draw-view ((self lightness-range-slider) &key viewport) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (low (slider-low-level-of self)) (hi (slider-high-level-of self)) (hue (if (slider-hue-of self) (mod (slider-hue-of self) 360))) (base-one (- (max-level self) (min-level self))) (flip (flip-range? self))) (case (orientation-of self) (:horizontal (let* ((begin low) (end hi) x-pos) (loop for x from begin to end do (setf x-pos (truncate (+ (x-shift map) (* x (x-scale map))))) (wb:canvas-draw-line (window-of vp) x-pos b x-pos tp :color (apply #'wb::make-color (wb:lhs_to_rgb (if flip (- 1 (/ x base-one)) (/ x base-one)) hue (slider-saturation-of self) :model (color-model-of self)) ))) ) ) (:vertical (let* ((begin low) (end hi) y-pos) (loop for y from begin to end do (setf y-pos (truncate (+ (y-shift map) (* y (y-scale map))))) (wb:canvas-draw-line (window-of vp) l y-pos r y-pos :color (apply #'wb::make-color (wb:lhs_to_rgb (if flip (- 1 (/ y base-one)) (/ y base-one)) hue (slider-saturation-of self) :model (color-model-of self)) )) )))) )))) (defmethod left-button-fn ((self range-slider-mixin) &key viewport ) (let* ((lbf (left-fn-of self)) (args (mapcar #'eval (target-of self))) (vlist (member :viewport args))) (if vlist (push viewport (cdr vlist))) ; (control-start self) (unwind-protect (if lbf (apply lbf args)) ; (if (toggle-control self) ; (control-done self)) ) ) ) (defmethod erase-slider ((self range-slider-mixin) &key viewport ) ;erases conservatively, only portions are erased (with-exposed-viewports self viewport vp (let* ((w (window-of vp)) (map (select-map-to-viewport self vp)) (low (slider-low-level-of self)) (hi (slider-high-level-of self)) rl rb rw rh temp1 temp2) (when vp (setq rl (left-of vp)) (setq rb (bottom-of vp)) (setq rw (width-of vp)) (setq rh (height-of vp)) (case (orientation-of self) (:horizontal (setf temp1 (truncate (+ (x-shift map) (* low (x-scale map))))) (setf temp2 (truncate (+ (x-shift map) (* hi (x-scale map))))) (wb::canvas-clear w :canvas-left rl :canvas-bottom (+ rb -1) :width (+ rl temp1) :height (+ 1 rh) ) (wb::canvas-clear w :canvas-left (+ temp2 1) :canvas-bottom (+ rb -1) :width (+ rl (- rw temp2)) :height (+ 1 rh)) ) (:vertical (setf temp1 (truncate (+ (y-shift map) (* low (y-scale map))))) (setf temp2 (truncate (+ (y-shift map) (* hi (y-scale map))))) (wb::canvas-clear w :canvas-left rl :canvas-bottom (+ rb (- temp2 rb) -1) :width (+ 1 rw) :height (- rh (- temp2 rb)) ) (wb::canvas-clear w :canvas-left rl :canvas-bottom (+ rb -1) :width (+ 1 rw) :height (- temp1 rb) ) ) ) (when (box-p self) (draw-viewport vp :color (draw-style self :box-color) :margin (box-margin-of self))) )))) ;maybe draw a few repeat lines to get rid of sometimes occuring missing lines (defmethod set-slider-level ((self lightness-range-slider) &key low-level high-level viewport position) (if (and (null low-level) (null high-level) position) (let* ((pos-local (apply-transform (invert-transform (select-map-to-viewport self viewport) ) position)) (new (if (eql (orientation-of self) :horizontal) (2d-position-x pos-local) (2d-position-y pos-local)))) (if (< (abs (- new (slider-low-level-of self))) (abs (- new (slider-high-level-of self)))) (setq low-level new high-level (slider-high-level-of self) ) (setq high-level new low-level (slider-low-level-of self) )))) (if (slider-step-of self) (setf low-level (* (slider-step-of self) (truncate low-level (slider-step-of self))) high-level (* (slider-step-of self) (truncate high-level (slider-step-of self))) )) (setf low-level (max (min-level self) (min low-level (max-level self))) high-level (max (min-level self) (min high-level (max-level self)))) (unless (and (= low-level (slider-low-level-of self)) (= high-level (slider-high-level-of self))) (cond ((< (slider-low-level-of self) low-level (slider-high-level-of self)) ;(erase-slider self :low-level low-level :high-level (slider-high-level-of self)) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (old (slider-low-level-of self)) (new low-level) ) (case (orientation-of self) (:horizontal (let ((begin (truncate (+ (x-shift map) (* old (x-scale map))))) (end (truncate (+ (x-shift map) (* new (x-scale map))))) ) (wb::canvas-clear (window-of vp) :canvas-left begin :canvas-bottom b :width (- end begin) :height (- tp b)))) (:vertical (let ((begin (truncate (+ (y-shift map) (* old (y-scale map))))) (end (truncate (+ (y-shift map) (* new (y-scale map))))) ) (wb::canvas-clear (window-of vp) :canvas-left l :canvas-bottom begin :width (- r l) :height (- end begin)))) ) ))) (setf (slider-low-level-of self) low-level) ) ((< (slider-low-level-of self) high-level (slider-high-level-of self)) ;(erase-slider self :low-level (slider-low-level-of self) :high-level high-level) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (old (slider-high-level-of self)) (new high-level) ;(new (+ 1 high-level)) ) (case (orientation-of self) (:horizontal (let ((begin (truncate (+ (x-shift map) (* new (x-scale map))))) (end (truncate (+ (x-shift map) (* old (x-scale map))))) ) (wb::canvas-clear (window-of vp) :canvas-left begin :canvas-bottom b :width (- end begin) :height (- tp b)))) (:vertical (let ((begin (truncate (+ (y-shift map) (* new (y-scale map))))) (end (truncate (+ (y-shift map) (* old (y-scale map))))) ) (wb::canvas-clear (window-of vp) :canvas-left l :canvas-bottom begin :width (- r l) :height (- end begin)))) ) ))) (setf (slider-high-level-of self) high-level) ) ((< (slider-high-level-of self) high-level) ; (draw-view self) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (hue (if (slider-hue-of self) (mod (slider-hue-of self) 360))) (base-one (- (max-level self) (min-level self))) (flip (flip-range? self))) (case (orientation-of self) (:horizontal (let* ((begin (slider-high-level-of self) ) (end high-level) x-pos) (loop for x from begin to end do (setf x-pos (truncate (+ (x-shift map) (* x (x-scale map))))) (wb:canvas-draw-line (window-of vp) x-pos b x-pos tp :color (apply #'wb::make-color (wb:lhs_to_rgb (if flip (- 1 (/ x base-one)) (/ x base-one)) hue (slider-saturation-of self) :model (color-model-of self)) )) ) )) (:vertical (let* ((begin (slider-high-level-of self) ) (end high-level) y-pos) (loop for y from (+ begin 1) to end do (setf y-pos (truncate (+ (y-shift map) (* y (y-scale map))))) (wb:canvas-draw-line (window-of vp) l y-pos r y-pos :color (apply #'wb::make-color (wb:lhs_to_rgb (if flip (- 1 (/ y base-one)) (/ y base-one)) hue (slider-saturation-of self) :model (color-model-of self)) )) ))))))) (setf (slider-high-level-of self) high-level) ) ((> (slider-low-level-of self) low-level) ; (draw-view self) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (hue (if (slider-hue-of self) (mod (slider-hue-of self) 360))) (base-one (- (max-level self) (min-level self))) (flip (flip-range? self))) (case (orientation-of self) (:horizontal (let* ((begin low-level) (end (slider-low-level-of self)) x-pos) (loop for x from begin to end do (setf x-pos (truncate (+ (x-shift map) (* x (x-scale map))))) (wb:canvas-draw-line (window-of vp) x-pos b x-pos tp :color (apply #'wb::make-color (wb:lhs_to_rgb (if flip (- 1 (/ x base-one)) (/ x base-one)) hue (slider-saturation-of self) :model (color-model-of self)) )) ) )) (:vertical (let* ((begin low-level) (end (slider-low-level-of self)) y-pos) (loop for y from (+ begin 1) to end do (setf y-pos (truncate (+ (y-shift map) (* y (y-scale map))))) (wb:canvas-draw-line (window-of vp) l y-pos r y-pos :color (apply #'wb::make-color (wb:lhs_to_rgb (if flip (- 1 (/ y base-one)) (/ y base-one)) hue (slider-saturation-of self) :model (color-model-of self)) )) ))))))) (setf (slider-low-level-of self) low-level) ) ) (when (box-p self) (draw-viewport viewport :color (draw-style self :box-color) :margin (box-margin-of self))) )) (defmethod set-slider-level ((self hue-range-slider) &key low-level high-level viewport position) (if (and (null low-level) (null high-level) position) (let* ((pos-local (apply-transform (invert-transform (select-map-to-viewport self viewport) ) position)) (new (if (eql (orientation-of self) :horizontal) (2d-position-x pos-local) (2d-position-y pos-local)))) (if (< (abs (- new (slider-low-level-of self))) (abs (- new (slider-high-level-of self)))) (setq low-level new high-level (slider-high-level-of self) ) (setq high-level new low-level (slider-low-level-of self) )))) (if (slider-step-of self) (setf low-level (* (slider-step-of self) (truncate low-level (slider-step-of self))) high-level (* (slider-step-of self) (truncate high-level (slider-step-of self))))) (setf low-level (max (min-level self) (min low-level (max-level self))) high-level (max (min-level self) (min high-level (max-level self)))) (unless (and (= low-level (slider-low-level-of self)) (= high-level (slider-high-level-of self))) (cond ((< (slider-low-level-of self) low-level (slider-high-level-of self)) ;(erase-slider self :low-level low-level :high-level (slider-high-level-of self)) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (old (slider-low-level-of self)) (new low-level) ) (case (orientation-of self) (:horizontal (let ((begin (truncate (+ (x-shift map) (* old (x-scale map))))) (end (truncate (+ (x-shift map) (* new (x-scale map))))) ) (wb::canvas-clear (window-of vp) :canvas-left begin :canvas-bottom b :width (- end begin) :height (- tp b)))) (:vertical (let ((begin (truncate (+ (y-shift map) (* old (y-scale map))))) (end (truncate (+ (y-shift map) (* new (y-scale map))))) ) (wb::canvas-clear (window-of vp) :canvas-left l :canvas-bottom begin :width (- r l) :height (- end begin)))) ) ))) (setf (slider-low-level-of self) low-level) ) ((< (slider-low-level-of self) high-level (slider-high-level-of self)) ;(erase-slider self :low-level (slider-low-level-of self) :high-level high-level) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (old (slider-high-level-of self)) (new high-level) ;(new (+ 1 high-level)) ) (case (orientation-of self) (:horizontal (let ((begin (truncate (+ (x-shift map) (* new (x-scale map))))) (end (truncate (+ (x-shift map) (* old (x-scale map))))) ) (wb::canvas-clear (window-of vp) :canvas-left begin :canvas-bottom b :width (- end begin) :height (- tp b)))) (:vertical (let ((begin (truncate (+ (y-shift map) (* new (y-scale map))))) (end (truncate (+ (y-shift map) (* old (y-scale map))))) ) (wb::canvas-clear (window-of vp) :canvas-left l :canvas-bottom begin :width (- r l) :height (- end begin)))) ) ))) (setf (slider-high-level-of self) high-level) ) ((< (slider-high-level-of self) high-level) ; (draw-view self) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (flip (flip-range? self))) (case (orientation-of self) (:horizontal (let* ((begin (slider-high-level-of self)) (end high-level) x-pos) (loop for x from begin to end do (setf x-pos (truncate (+ (x-shift map) (* x (x-scale map))))) (wb:canvas-draw-line (window-of vp) x-pos b x-pos tp :color (apply #'wb::make-color (wb:lhs_to_rgb (slider-lightness-of self) (if flip (- 359 (mod x 360)) (mod x 360)) (slider-saturation-of self) :model (color-model-of self)) )) ) )) (:vertical (let* ((begin (slider-high-level-of self)) (end high-level) y-pos) (loop for y from (+ begin 1) to end do (setf y-pos (truncate (+ (y-shift map) (* y (y-scale map))))) (wb:canvas-draw-line (window-of vp) l y-pos r y-pos :color (apply #'wb::make-color (wb:lhs_to_rgb (slider-lightness-of self) (if flip (- 359 (mod y 360)) (mod y 360)) (slider-saturation-of self) :model (color-model-of self)) )) ))))))) (setf (slider-high-level-of self) high-level) ) ((> (slider-low-level-of self) low-level) ; (draw-view self) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (flip (flip-range? self))) (case (orientation-of self) (:horizontal (let* ((begin low-level) (end (slider-low-level-of self)) x-pos) (loop for x from begin to end do (setf x-pos (truncate (+ (x-shift map) (* x (x-scale map))))) (wb:canvas-draw-line (window-of vp) x-pos b x-pos tp :color (apply #'wb::make-color (wb:lhs_to_rgb (slider-lightness-of self) (if flip (- 359 (mod x 360)) (mod x 360)) (slider-saturation-of self) :model (color-model-of self)) )) ) )) (:vertical (let* ((begin low-level) (end (slider-low-level-of self)) y-pos) (loop for y from begin to end do (setf y-pos (truncate (+ (y-shift map) (* y (y-scale map))))) (wb:canvas-draw-line (window-of vp) l y-pos r y-pos :color (apply #'wb::make-color (wb:lhs_to_rgb (slider-lightness-of self) (if flip (- 359 (mod y 360)) (mod y 360)) (slider-saturation-of self) :model (color-model-of self)) )) ))))))) (setf (slider-low-level-of self) low-level) ) ) (when (box-p self) (draw-viewport viewport :color (draw-style self :box-color) :margin (box-margin-of self))) ))
27,785
Common Lisp
.l
614
26.027687
128
0.400902
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
bb49e4f29b6b6c8e49af5bb03a27de09c2f14bb8b86e7deedcb58126f9a31d29
33,218
[ -1 ]
33,219
slider.lsp
rwoldford_Quail/source/views/controls/slider.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; slider.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical ;;; graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; N. Wiebe 1998-1999 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(slider slider-mixin slider-level-of min-level max-level bar-slider needle-slider))) ;;;---------------------------------------------------------------------------------- (setq *default-slider-color* *default-point-color*) (defclass slider-mixin (control-mixin boxed-view-mixin orientation-mixin tic-mixin ) ((style-keys :initform '(:color :box-color) :allocation :class ) (step :accessor slider-step-of :initarg :step :initform nil ) (middle-menu :allocation :class :initform nil)) (:default-initargs :min 0.0 :max 1.0 :color *default-slider-color* )) (defclass slider (slider-mixin simple-view ) ((level :accessor slider-level-of :initarg :level :initform nil ) (continuous-action-fn :accessor continuous-action-fn-of :initarg :continuous-action-fn :initform nil :documentation "A function of no arguments to be fired as the slider level ~ changes value."))) (defclass bar-slider (slider) ()) (defclass needle-slider (slider) ((style-keys :initform '(:color :needle-size :box-color) :allocation :class)) (:default-initargs :needle-size 20 )) (defmethod initialize-instance :after ((self slider) &key) (if (null (slider-level-of self)) (setf (slider-level-of self) (/ (+ (min-level self) (max-level self)) 2.0)))) (defmethod min-level ((self slider-mixin)) (ecase (orientation-of self) (:horizontal (left-of (bounding-region-of self))) (:vertical (bottom-of (bounding-region-of self))))) (defmethod max-level ((self slider-mixin)) (ecase (orientation-of self) (:horizontal (right-of (bounding-region-of self))) (:vertical (top-of (bounding-region-of self))))) (defmethod get-map-portion ((self needle-slider) viewport) (let ((adjust-vp (copy-region viewport)) (ns (truncate (draw-style self :needle-size) 2))) (ecase (orientation-of self) (:horizontal (incf (left-of adjust-vp) ns) (decf (right-of adjust-vp) ns)) (:vertical (incf (bottom-of adjust-vp) ns) (decf (top-of adjust-vp) ns))) adjust-vp)) #| (defmethod get-draw-portion ((self needle-slider) viewport) viewport) |# (defmethod draw-view ((self bar-slider) &key viewport) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (level (or (slider-level-of self) 0)) (x-wid (- r l)) (y-wid (- tp b))) (if (eql (orientation-of self) :horizontal) (setq x-wid (round (* level (x-scale map)))) (setq y-wid (round (* level (y-scale map))))) (wb:canvas-draw-filled-rectangle (window-of vp) l (+ l x-wid) b (+ b y-wid) :color (draw-style self :color)))))) (defmethod erase-slider ((self slider-mixin) &key viewport &allow-other-keys ) (erase-view self :viewport viewport)) (defmethod erase-slider ((self bar-slider) &key viewport level) (let ((old-level (or (slider-level-of self) 0)) ) (when (< level old-level) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) )) (if (eql (orientation-of self) :horizontal) (setq l (round (+ (x-shift map) (* level (x-scale map)))) r (round (+ (x-shift map) (* old-level (x-scale map))))) (setq b (round (+ (y-shift map) (* level (y-scale map)))) tp (round (+ (y-shift map) (* old-level (y-scale map)))))) (wb:canvas-clear (window-of vp) :canvas-left l :canvas-bottom b :width (+ 1 (- r l)) :height (+ 1 (- tp b))))))))) (defmethod draw-view ((self needle-slider) &key viewport) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (level (or (slider-level-of self) 0)) (ns (truncate (draw-style self :needle-size) 2))) (if (eql (orientation-of self) :horizontal) (setq r (round (+ ns (x-shift map) (* level (x-scale map)))) l (round (+ (- ns) (x-shift map) (* level (x-scale map))))) (setq tp (round (+ ns (y-shift map) (* level (y-scale map)))) b (round (+ (- ns) (y-shift map) (* level (y-scale map)))))) (let ((colour1 wb::*light-gray-colour*) (colour2 wb::*dark-gray-colour*) (colour3 wb::*default-canvas-pen-color*) (colour4 wb::*gray-colour*) (width 3) ;;width between lines (lw 1) ;; line width (num (min 3 (truncate ns 4)))) ;; max 3 lines above/below centre line (wb:canvas-draw-filled-rectangle (window-of vp) l r b tp :color colour4) (wb:canvas-draw-rectangle (window-of vp) l r b tp :color colour3) ; or (wb:canvas-draw-inside-rectangle (window-of vp) l r b tp :color colour3) ; (wb:canvas-draw-rectangle (window-of vp) (- l 1) r b (+ tp 1) :colorcolour3) (if (eql (orientation-of self) :horizontal) (let* ((indent-fraction 0.1) (indent (truncate (* indent-fraction (height-of vp)))) (middle (truncate (+ l r 1) 2))) (wb:canvas-draw-line (window-of vp) middle (+ b (truncate indent 2)) middle (- tp (truncate indent 2)) :color colour2) (wb:canvas-draw-line (window-of vp) (+ lw middle) (+ b (truncate indent 2)) (+ lw middle) (- tp (truncate indent 2)) :color colour1) (do ((index 0 (+ index 1)) (vert (+ middle width) (+ vert width))) ((= index num)) (wb:canvas-draw-line (window-of vp) vert (+ b indent) vert (- tp indent) :color colour2) (wb:canvas-draw-line (window-of vp) (+ lw vert) (+ b indent) (+ lw vert) (- tp indent) :color colour1)) (do ((index 0 (+ index 1)) (vert (- middle width) (- vert width))) ((= index num)) (wb:canvas-draw-line (window-of vp) vert (+ b indent) vert (- tp indent) :color colour2) (wb:canvas-draw-line (window-of vp) (+ lw vert) (+ b indent) (+ lw vert) (- tp indent) :color colour1))) (let* ((indent-fraction 0.1) (indent (truncate (* indent-fraction (width-of vp)))) (middle (truncate (+ b tp) 2))) (wb:canvas-draw-line (window-of vp) (+ l (truncate indent 2)) middle (- r (truncate indent 2)) middle :color colour2) (wb:canvas-draw-line (window-of vp) (+ l (round indent 2)) (+ lw middle) (- r (round indent 2)) (+ lw middle) :color colour1) (do ((index 0 (+ index 1)) (hor (+ middle width) (+ hor width))) ((= index num)) (wb:canvas-draw-line (window-of vp) (+ l indent) hor (- r indent) hor :color colour2) (wb:canvas-draw-line (window-of vp) (+ l indent) (+ lw hor) (- r indent) (+ lw hor) :color colour1)) (do ((index 0 (+ index 1)) (hor (- middle width) (- hor width))) ((= index num)) (wb:canvas-draw-line (window-of vp) (+ l indent) hor (- r indent) hor :color colour2) (wb:canvas-draw-line (window-of vp) (+ l indent) (+ lw hor) (- r indent) (+ lw hor) :color colour1)) ))) )))) (defmethod erase-slider ((self needle-slider) &key viewport) (with-exposed-viewports self viewport vp (multiple-value-bind (l r b tp) (bounds-of vp) (let ((map (select-map-to-viewport self vp) ) (level (or (slider-level-of self) 0)) (ns (truncate (draw-style self :needle-size) 2))) (if (eql (orientation-of self) :horizontal) (setq r (round (+ ns (x-shift map) (* level (x-scale map)))) l (round (+ (- ns) (x-shift map) (* level (x-scale map))))) (setq tp (round (+ ns (y-shift map) (* level (y-scale map)))) b (round (+ (- ns) (y-shift map) (* level (y-scale map)))))) (if (eql (orientation-of self) :horizontal) (wb:canvas-clear (window-of vp) :canvas-left l :canvas-bottom b :width (+ 1 (- r l)) :height (- tp b 1)) (wb:canvas-clear (window-of vp) :canvas-left (+ 1 l) :canvas-bottom (- b 1) :width (- r l 1) :height (+ 2 (- tp b))) ; (wb:canvas-clear ; (window-of vp) :canvas-left (- l 1) :canvas-bottom b ; :width (+ 2 (- r l)) :height (- tp b)) ; (wb:canvas-clear ; (window-of vp) :canvas-left l :canvas-bottom (- b 1) ; :width (- r l) :height (+ 2 (- tp b))) ))))) (defmethod get-menu-items :around ((self slider-mixin) (slot-name (eql 'middle-menu)))) (defmethod set-slider-level ((self slider) &key level viewport position) (setq level (or level (let ((pos-local (apply-transform (invert-transform (select-map-to-viewport self viewport) ) position))) (if (eql (orientation-of self) :horizontal) (2d-position-x pos-local) (2d-position-y pos-local))))) (if (slider-step-of self) (setf level (* (slider-step-of self) (round level (slider-step-of self))))) (setf level (max (min-level self) (min level (max-level self)))) (when (not (= level (slider-level-of self))) (erase-slider self :level level) (setf (slider-level-of self) level) (draw-view self) (let ((af (continuous-action-fn-of self))) (when (functionp af) (funcall af))))) (defmethod left-button-fn :before ((self slider-mixin) &key viewport position) (declare (ignore position)) (loop while (wb:mouse-down-p) do ;;(sleep 0.1) (set-slider-level self :viewport viewport :position (view-position (wb:mouse-position (window-of viewport)))))) (defmethod use-x-axis-p ((self slider-mixin)) (eql (orientation-of self) :horizontal)) (defmethod use-y-axis-p ((self slider-mixin)) (eql (orientation-of self) :vertical))
12,566
Common Lisp
.l
240
38.175
150
0.489635
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d90862f5330ab4f717e35409d1e0f7e21e1b009eca519aab5a4b3e0a1b571b31
33,219
[ -1 ]
33,220
signpost-button.lsp
rwoldford_Quail/source/views/controls/signpost-button.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; signpost-button.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; N. Wiebe 1998 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(signpost-button))) ;;---------------------------------------------------------------------- (defvar *signpost-button-text-color* wb::*black-color*) (defvar *signpost-button-color* wb::*gray-color*) (defclass signpost-button (control-mixin label) ((style-keys :initform '(:button-color :font :color) :allocation :class) (button-height :initform 2 :initarg :button-height :accessor button-height :documentation "Perceived 3d height of the button above ~ the screen in pixels.") (max-height :initform 25 :initarg :max-height :accessor max-height :documentation "Maximum height of the button") (max-width :initform 100 :initarg :max-width :accessor max-width :documentation "Maximum width of the button")) (:default-initargs :font wb:*small-graphics-font* :color *signpost-button-text-color* :button-color *signpost-button-color* :justification :left )) (defun signpost-button (&rest keyword-args &key (text "Unnamed signpost") (text-color *signpost-button-text-color*) (font wb:*small-graphics-font*) (button-color *signpost-button-color*) (button-fn NIL) (draw? NIL) ) (declare (ignore draw? font button-color)) ; 29JUL2023 (apply #'make-instance 'signpost-button :text text :color text-color :left-fn button-fn keyword-args)) (defmethod selected-p ((self signpost-button) viewport location) ;; is view selected with mouse at location? ;; default looks to see if location is in viewport (let* ((width (width-of viewport)) (height (height-of viewport)) (mwidth (max-width self)) (mheight (max-height self)) (x-centre (+ (left-of viewport) (/ width 2))) (y-centre (+ (bottom-of viewport) (/ height 2))) p left right top bottom mid-vert mid-hor slope y-intercept1 y-intercept2 x y half-width half-height) (setf mwidth (if (eq mwidth :viewport) width mwidth)) (setf mheight (if (eq mheight :viewport) height mheight)) (setf p (min (/ width mwidth) (/ height mheight) 1)) (setf width (* p mwidth)) (setf half-width (/ width 2)) (setf height (* p mheight)) (setf half-height (/ height 2)) (setf left (round (- x-centre half-width))) (setf right (round (+ x-centre half-width))) (setf top (round (+ y-centre half-height))) (setf bottom (round (- y-centre half-height))) (setf mid-vert (round (/ (+ top bottom) 2))) (setf mid-hor (round (+ (/ (* width 4) 5) left))) (setf slope (/ (- mid-vert bottom) (- right mid-hor))) (setf y-intercept1 (- mid-vert (* slope right))) (setf y-intercept2 (- mid-vert (* -1 slope right))) (setf x (elt location 0)) (setf y (elt location 1)) (and (active-viewport-p viewport) (or (and (>= x left) (<= x mid-hor) (>= y bottom) (<= y top)) (and (> x mid-hor) (<= x right) (>= y (+ (* slope x) y-intercept1)) (<= y (+ (* -1 slope x) y-intercept2))))))) (defmethod draw-view ((self signpost-button) &key viewport) (let ((just (justification-of self)) (dir (orientation-of self)) (font (draw-style self :font)) (col (draw-style self :color)) (string (get-text self)) (button-color (draw-style self :button-color))) (unless (wb::canvas-font-p font) (setq font (let ((vp (car (viewports-of self)))) (wb::canvas-make-font :size (max 7 (min 16 (truncate (* 0.5 (min (width-of vp) (height-of vp))))))))) (set-draw-style self :font font)) (if (null dir) (let ((vp (car (viewports-of self)))) (setf (orientation-of self) (setq dir (if (> (height-of vp) (width-of vp)) :vertical :horizontal))))) (with-exposed-viewports self viewport vp (let* ((canvas (window-of vp)) (width (width-of vp)) (height (height-of vp)) (mwidth (if (eq (max-width self) :viewport) width (max-width self))) (mheight (if (eq (max-height self) :viewport) height (max-height self))) (p (min (/ width mwidth) (/ height mheight) 1)) (x-centre (+ (left-of vp) (/ width 2))) (y-centre (+ (bottom-of vp) (/ height 2))) (width (* p mwidth)) (half-width (/ width 2)) (height (* p mheight)) (half-height (/ height 2)) (left (round (- x-centre half-width))) (right (round (+ x-centre half-width))) (top (round (+ y-centre half-height))) (bottom (round (- y-centre half-height))) (mid-vert (round (/ (+ top bottom) 2))) (mid-hor (round (+ (/ (* width 4) 5) left))) left-top-colour bottom-right-colour (button-height (truncate (abs (button-height self)))) (half-button-height (truncate button-height 2)) ) (cond ((vw::control-state self) (setf left-top-colour (wb::darken button-color)) (setf bottom-right-colour (wb::lighten button-color)) ) (T (setf left-top-colour (wb::lighten button-color)) (setf bottom-right-colour (wb::darken button-color)) ) ) (wb::canvas-draw-filled-polygon canvas (list (cons left bottom) (cons left top) (cons mid-hor top) (cons right mid-vert) (cons mid-hor bottom)) :color button-color) (wb::canvas-draw-line canvas left top mid-hor top :width button-height :color left-top-colour) (wb::canvas-draw-line canvas mid-hor top right mid-vert :width button-height :color (wb::lighten button-color :factor .1)) (wb::canvas-draw-line canvas right mid-vert mid-hor bottom :width button-height :color bottom-right-colour) (wb::canvas-draw-line canvas mid-hor bottom left bottom :width button-height :color bottom-right-colour) (wb::canvas-draw-line canvas left bottom left top :width button-height :color left-top-colour) (wb::canvas-draw-line canvas (- left half-button-height) (+ half-button-height top) (+ button-height mid-hor) (+ half-button-height top) :width 1 :color wb::*black-colour*) (wb::canvas-draw-line canvas (+ button-height mid-hor) (+ half-button-height top) (+ 1 button-height right) mid-vert :width 1 :color wb::*black-colour*) (wb::canvas-draw-line canvas (+ 1 button-height right) mid-vert (+ button-height mid-hor) (- bottom button-height) :width 1 :color wb::*black-colour*) (wb::canvas-draw-line canvas (+ button-height mid-hor) (- bottom button-height) (- left half-button-height) (- bottom button-height) :width 1 :color wb::*black-colour*) (wb::canvas-draw-line canvas (- left half-button-height) (- bottom button-height) (- left half-button-height) (+ half-button-height top) :width 1 :color wb::*black-colour*) (wb::canvas-draw-string canvas string :left (+ left (* 3 button-height)) :width (- width button-height button-height) :bottom (+ bottom button-height) :height (- height button-height button-height) :font font :orientation dir :clip? t :justification just :color col) ) )))
9,600
Common Lisp
.l
199
33.633166
145
0.48467
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4920856f9a494951f16b7c89459f7a6e65db683b3ca20b80224672389fc71413
33,220
[ -1 ]
33,221
elliptical-button.lsp
rwoldford_Quail/source/views/controls/elliptical-button.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; elliptical-button.lsp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; N. Wiebe 1998 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(elliptical-button))) ;;---------------------------------------------------------------------- (defvar *elliptical-button-text-color* *black-color*) (defvar *elliptical-button-color* *gray-color*) (defclass elliptical-button (control-mixin label) ((style-keys :initform '(:button-color :font :color) :allocation :class) (button-height :initform 2 :initarg :button-height :accessor button-height :documentation "Perceived 3d height of the button above ~ the screen in pixels.") (diameter-x :initform :viewport :initarg :diameter-x :accessor diameter-x :documentation "Maximum diameter in the horizontal direction") (diameter-y :initform :viewport :initarg :diameter-y :accessor diameter-y :documentation "Maximum diameter in the vertical direction")) (:default-initargs :font wb::*small-graphics-font* :color *elliptical-button-text-color* :button-color *elliptical-button-color* )) (defmethod selected-p ((self elliptical-button) viewport location) ;; is view selected with mouse at location? ;; default looks to see if location is in viewport (let* ((width (width-of viewport)) (height (height-of viewport)) (diamx (diameter-x self)) (diamx (if (eq diamx :viewport) width diamx)) (diamy (diameter-y self)) (diamy (if (eq diamy :viewport) height diamy)) (p (min (/ width diamx) (/ height diamy) 1)) (x-centre (round (+ (left-of viewport) (/ width 2)))) (y-centre (round (+ (bottom-of viewport) (/ height 2)))) (diameter-x (* p diamx)) (x-radius (round (/ diameter-x 2))) (diameter-y (* p diamy)) (y-radius (round (/ diameter-y 2))) (left (- x-centre x-radius)) (right (+ x-centre x-radius)) (x (elt location 0)) (y (elt location 1))) (and (active-viewport-p viewport) (>= x left) (<= x right) (or (and (>= y y-centre) (<= y (+ y-centre (sqrt (* (** y-radius 2) (- 1 (/ (** (- x x-centre) 2) (** x-radius 2)))))))) (and (< y y-centre) (>= y (+ y-centre (* -1 (sqrt (* (** y-radius 2) (- 1 (/ (** (- x x-centre) 2) (** x-radius 2))))))))))))) (defmethod draw-view ((self elliptical-button) &key viewport) (let ((just (vw::justification-of self)) (dir (orientation-of self)) (font (draw-style self :font)) (col (draw-style self :color)) (string (get-text self)) (button-color (draw-style self :button-color))) (unless (wb::canvas-font-p font) (setq font (let ((vp (car (viewports-of self)))) (wb::canvas-make-font :size (max 7 (min 16 (truncate (* 0.5 (min (width-of vp) (height-of vp))))))))) (set-draw-style self :font font)) (if (null dir) (let ((vp (car (viewports-of self)))) (setf (orientation-of self) (setq dir (if (> (height-of vp) (width-of vp)) :vertical :horizontal))))) (with-exposed-viewports self viewport vp (let* ((canvas (window-of vp)) (width (width-of vp)) (height (height-of vp)) (diamx (diameter-x self)) (diamx (if (eq diamx :viewport) width diamx)) (diamy (diameter-y self)) (diamy (if (eq diamy :viewport) height diamy)) (p (min (/ width diamx) (/ height diamy) 1)) (x-centre (round (+ (left-of vp) (/ width 2)))) (y-centre (round (+ (bottom-of vp) (/ height 2)))) (diameter-x (* p diamx)) (x-radius (round (/ diameter-x 2))) (diameter-y (* p diamy)) (y-radius (round (/ diameter-y 2))) colour1 colour2 colour3 (button-height (truncate (abs (button-height self)))) (half-button-height (truncate button-height 2)) ) (cond ((vw::control-state self) (setf colour1 (wb::darken button-color)) (setf colour2 (wb::lighten button-color :factor .1)) (setf colour3 (wb::lighten button-color)) ) (T (setf colour1 (wb::lighten button-color)) (setf colour2 (wb::lighten button-color :factor .1)) (setf colour3 (wb::darken button-color)) ) ) (wb::canvas-draw-filled-arc canvas 65 360 x-centre y-centre x-radius y-radius :color button-color) (wb::canvas-draw-arc canvas 15 60 x-centre y-centre x-radius y-radius :width button-height :color colour2) (wb::canvas-draw-arc canvas 75 120 x-centre y-centre x-radius y-radius :width button-height :color colour1) (wb::canvas-draw-arc canvas 195 60 x-centre y-centre x-radius y-radius :width button-height :color colour2) (wb::canvas-draw-arc canvas 255 120 x-centre y-centre x-radius y-radius :width button-height :color colour3) (wb::canvas-draw-arc canvas 65 360 x-centre y-centre (+ x-radius half-button-height) (+ y-radius half-button-height) :width 1 :color wb::*black-colour*) (wb::canvas-draw-string canvas string :left (+ (- x-centre x-radius) button-height) :width (round (- diameter-x button-height button-height)) :bottom (+ (- y-centre y-radius) button-height) :height (round (- diameter-y button-height button-height)) :font font :orientation dir :clip? t :justification just :color col) ) )))
7,439
Common Lisp
.l
160
31.7625
110
0.462691
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
60dd7cdc5dff3de451c264d7deb71f7ff1095216c39fec2b86bdf33f0018d0f9
33,221
[ -1 ]
33,222
display-data.lsp
rwoldford_Quail/source/views/display/display-data.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; display-data.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993, 1995, 1999 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(dataset-view case-view))) (defun dataset-view (&rest keyword-args &key (data NIL) (draw? NIL) (viewport NIL) (signposts? T) &allow-other-keys) (unless data (setf data (choose-dataset))) (if (= 1 (length (list-cases data))) (apply #'case-view data :draw? draw? :signposts? signposts? :vars (list-variates data) keyword-args) (let* ((cases (case-display-list :data data :draw? NIL :scrollable? T :link? T)) (vars (variate-display-list :data data :draw? NIL :scrollable? T :link? T)) (name (text-view :text (dataset-name data) :draw? NIL)) (var-label (text-view :text (format NIL "Variates (~s)" (length (list-variates data))) :draw? NIL)) (case-label (text-view :text (format NIL "Cases (~s)" (length (list-cases data))) :draw? NIL)) (title (text-view :text "Dataset:" :draw? NIL)) (hline1 (line :slope 0 :intercept 0.5 :viewed-object data)) (signpost-view (if signposts? (signposts data :as-dataset? T))) result) (setf result (cond (signpost-view (apply #'view-layout :viewed-object data :subviews (list title name case-label cases var-label vars hline1 signpost-view) :positions '((0 20 90 100) (20 80 90 100) (2 20 80 90) (2 40 0 80) (42 62 80 90) (42 80 0 80) (0 100 0 2) (0 100 -50 0)) :draw? NIL keyword-args)) (T (apply #'view-layout :viewed-object data :subviews (list title name case-label cases var-label vars hline1) :positions '((0 20 90 100) (20 80 90 100) (2 20 80 90) (2 40 0 80) (42 62 80 90) (42 80 0 80) (0 100 0 2)) :draw? NIL keyword-args) ) ) ) (when draw? (unless (viewport-p viewport) (setf viewport (make-viewport (make-view-window :left 10 :right (max 500 (- (wb::screen-width) 100)) :bottom (max 0 (- (wb::screen-height) 800)) :top (- (wb::screen-height) 100) :title (if (dataset-name data) (format NIL "Viewing ~a" (dataset-name data)) "Dataset View"))))) (draw-view result :viewport viewport)) result ) )) (defun case-view (c &rest keyword-args &key (draw? nil) name signposts? (viewport NIL) vars &allow-other-keys) (setq vars (or vars (list-variates c))) (let* ((var-display (variate-display-list :data c :scrollable? nil :title (or name (dataset-name c) "Case") :labels (mapcar #'variate-string-of vars) :display-list-border 2)) (list-vals (values-of c vars)) (value-display (display-list :data c :scrollable? nil :items (cons "" (mapcar #'princ-to-string list-vals)) :display-list-border 2 :item-type '(:justification :left))) var-title (signpost-view (if signposts? (signposts c :as-dataset? T))) result) (loop for val in list-vals ;; for var in vars for sub in (cdr (subviews-of value-display)) ;; do (setf (viewed-object-of sub) var) when (numberp val) do (change-class sub 'numerical-label) (setf (slot-value sub 'number) val) ) (if (and (member :bold (wb:canvas-font-styles)) (setq var-title (first (subviews-of var-display)))) (set-view-font var-title :style :bold)) (setq result (apply #'scrolling-display :data c :right-scroller nil :bottom-scroller nil :data c :gap 5 :displays (list var-display value-display) :draw? nil keyword-args)) (cond (signposts? (let* ((w (max 300 (draw-region-width result))) (h (+ 100 (draw-region-height result))) (results (view-layout :data c :subviews (list result signpost-view) :positions (list (make-region 0 w 100 (+ 100 (draw-region-height result))) (make-region 0 w 0 100)) :bounding-region (make-region 0 w 0 h)))) (when draw? (unless (viewport-p viewport) (setf viewport (make-viewport (make-view-window :title (if (dataset-name c) (format NIL "Viewing ~a" (dataset-name c)) "Case View") :left 10 :right (min (- (wb::screen-width) 40) (+ 25 w)) :bottom 10 :top (min (- (wb::screen-height) 40) (+ 25 h)))))) (draw-view results :viewport viewport)) results)) (t (when draw? (unless (viewport-p viewport) (setf viewport (make-viewport (make-view-window :title (if (dataset-name c) (format NIL "Viewing ~a" (dataset-name c)) "Case View") :left 10 :right (min (- (wb::screen-width) 40) (+ 25 (draw-region-width result))) :bottom 10 :top (min (- (wb::screen-height) 40) (+ 25 (draw-region-height result))))))) (draw-view result :viewport viewport)) result))))
8,125
Common Lisp
.l
176
25.414773
109
0.376354
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
2e9a27d946fa775ab63914a5066cc56deb41f91f686d47a5091f778ecffc462c
33,222
[ -1 ]
33,223
display-data.lis
rwoldford_Quail/source/views/display/display-data.lis
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; display-data.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993, 1995 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (export '(dataset-view case-view)) (defgeneric case-view (case &rest keyword-args) (:documentation "Produces a display of case. Keyword arguments are specialized by methods. ~ These will include at least view style arguments.")) (defmethod case-view ((case T) &rest keyword-args ) "A not very clever default display that just shows the printed representation ~ of thing in a text-view." (apply #'display case :as-dataset? nil keyword-args)) (defun dataset-view (&rest keyword-args &key (data NIL) (draw? NIL) (viewport NIL) (signposts? T) &allow-other-keys) (unless data (setf data (choose-dataset))) (if (= 1 (length (list-cases data))) (apply #'case-view data :draw? draw? :viewport viewport :signposts? signposts? keyword-args) (let* ((cases (case-display-list :data data :draw? NIL :scrollable? T :link? T)) (vars (variate-display-list :data data :draw? NIL :scrollable? T :link? T)) (name (text-view :text (dataset-name data) :draw? NIL)) (var-label (text-view :text (format NIL "Variates (~s)" (length (list-variates data))) :draw? NIL)) (case-label (text-view :text (format NIL "Cases (~s)" (length (list-cases data))) :draw? NIL)) (title (text-view :text "Dataset:" :draw? NIL)) (hline1 (line :slope 0 :intercept 0.5 :viewed-object data)) (signpost-view (if signposts? (signposts data :as-dataset? T) ) ) result) (setf result (cond (signpost-view (apply #'view-layout :viewed-object data :subviews (list title name case-label cases var-label vars hline1 signpost-view) :positions '((0 20 80 100) (20 80 80 100) (2 20 60 80) (2 40 0 60) (42 62 60 80) (42 80 0 60) (0 100 0 2) (0 100 -50 0)) :draw? NIL keyword-args)) (T (apply #'view-layout :viewed-object data :subviews (list title name case-label cases var-label vars hline1) :positions '((0 20 80 100) (20 80 80 100) (2 20 60 80) (2 40 0 60) (42 62 60 80) (42 80 0 60) (0 100 0 2)) :draw? NIL keyword-args) ) ) ) (when draw? (unless (viewport-p viewport) (setf viewport (make-viewport (make-view-window :left 10 :right (max 500 (- (wb::screen-width) 100)) :bottom (max 0 (- (wb::screen-height) 800)) :top (- (wb::screen-height) 100) :title (if (dataset-name data) (format NIL "Viewing ~a" (dataset-name data)) "Dataset View"))))) (draw-view result :viewport viewport)) result ) ))
4,962
Common Lisp
.l
125
21.224
90
0.351821
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ee99316571ffedee35ad0479a83b3433d92c82d19a34cb3d4bcc01a4c6c7bd70
33,223
[ -1 ]
33,224
display-methods.lsp
rwoldford_Quail/source/views/display/display-methods.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; display-methods.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993, 1995 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(dataset-view))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; DISPLAY default behaviours ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defmethod display ((thing T) &rest keyword-args &key (draw? T) &allow-other-keys) "A not very clever default display that just shows the printed representation ~ of thing in a text-view." (apply #'text-view :viewed-object thing :text (format NIL "~&~s" thing) :draw? draw? keyword-args) ) (defmethod display :around ((thing T) &rest keyword-args &key (viewed-object NIL viewed-object?) (draw? T) (new? NIL) (as-dataset? NIL) (signposts? NIL) &allow-other-keys) (if (and as-dataset? (dataset-p thing)) (apply #'dataset-view :data thing keyword-args) (if signposts? (let ((result (apply #'call-next-method thing :new? new? :draw? NIL :signposts? NIL keyword-args)) (signposts (apply #'signposts thing :draw? NIL keyword-args)) (hline1 (line :intercept 0.5 :slope 0 :draw? NIL)) (hline2 (line :intercept 0.5 :slope 0 :draw? NIL)) signposts-view) (unless viewed-object? (setf viewed-object thing)) (setf (viewed-object-of hline1) viewed-object) (setf (viewed-object-of hline2) viewed-object) (setf signposts-view (cond ((and signposts (listp signposts)) (grid-layout :ncols 5 :subviews signposts :draw? NIL :box-views? NIL :gap-x .05 :gap-y .05 :viewed-object viewed-object)) (signposts signposts))) (if signposts-view (apply #'view-layout :viewed-object viewed-object :subviews (list result hline1 signposts-view hline2) :positions '((0 100 20 100) (0 100 18 20) (10 90 2 18) (0 100 0 2)) :draw? draw? keyword-args) signposts)) (call-next-method)) ) )
3,196
Common Lisp
.l
80
27.3375
86
0.402321
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
cb2e41c74f7f84c3ce66db9fd1c18c168e7c95438a4fa1d17ad6179e063fc33c
33,224
[ -1 ]
33,225
signposts-methods.lsp
rwoldford_Quail/source/views/display/signposts-methods.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; signposts-methods.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993, 1995, 1996. ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; SIGNPOSTS ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Add do-nothing primary FEB 02, 1998 (defmethod signposts ((thing T) &rest keyword-args &key (viewed-object NIL viewed-object?) (ncols 5) &allow-other-keys) (declare (ignorable thing keyword-args viewed-object ncols)) ;(declare (ignore thing keyword-args viewed-object ncols)) ; 30JUL2023 (call-next-method)) (defmethod signposts :around ((thing T) &rest keyword-args &key (viewed-object NIL viewed-object?) (ncols 5) &allow-other-keys) (unless viewed-object? (setf viewed-object thing)) (let ((signposts (call-next-method))) (if (and signposts (listp signposts)) (apply #'grid-layout :ncols (max (length signposts) ncols) :subviews signposts :draw? NIL :box-views? NIL :gap-x .05 :gap-y .05 :viewed-object viewed-object :draw? NIL keyword-args) signposts) ) ) (defmethod signposts ((thing T) &rest keyword-args &key (as-dataset? NIL) &allow-other-keys) (if (dataset-p thing) (if as-dataset? (list (apply #'view-layout :subviews (list (label :viewed-object thing :text "Single variate" :justification '(:bottom :center)) (control-button :viewed-object thing :text "Plot" :left-fn #'(lambda () (prompt-plot :dim 1))) (control-button :viewed-object thing :text "Plot by" :left-fn #'(lambda () (prompt-plot-by :dim 1)))) :positions '((0 100 80 109) (0 100 40 79) (0 100 0 39)) :viewed-object thing keyword-args) (apply #'view-layout :subviews (list (label :viewed-object thing :text "Two variates" :justification '(:bottom :center)) (control-button :viewed-object thing :text "Plot" :left-fn #'(lambda () (prompt-plot :dim 2))) (control-button :viewed-object thing :text "Plot by" :left-fn #'(lambda () (prompt-plot-by :dim 2)))) :positions '((0 100 80 109) (0 100 40 79) (0 100 0 39)) :viewed-object thing keyword-args) (apply #'view-layout :subviews (list (label :viewed-object thing :text "Multiple variates" :justification '(:bottom :center)) (control-button :viewed-object thing :text "Plot" :left-fn #'(lambda () (prompt-plot :dim 3))) (control-button :viewed-object thing :text "Plot by" :left-fn #'(lambda () (batch-plot)))) :positions '((0 100 80 109) (0 100 40 79) (0 100 0 39)) :viewed-object thing keyword-args) ) (apply #'control-button :viewed-object thing :text "Display as dataset" :left-fn #'(lambda () (dataset-view :data thing :draw? T)) keyword-args) ) (apply #'control-button :viewed-object thing :text "Inspect" :left-fn #'(lambda () (inspect thing)) keyword-args) ) )
5,258
Common Lisp
.l
136
21.926471
135
0.358979
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4b05a032dd1decfc3901abd2417ed464de6ed4ff19135d5cd4bcf71a92c34031
33,225
[ -1 ]
33,226
display-list.lsp
rwoldford_Quail/source/views/display/display-list.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; display-list.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(display-list case-display-list variate-display-list sub-view-height draw-region-width draw-region-height display-length-of *display-items-limit* batch-display-list))) (defclass display-list (scrollable-view-mixin compound-view) ((border :initarg :display-list-border :initform 2 :accessor display-list-border-of) (subview-height :initarg :subview-height :initform nil :accessor subview-height-of) (subview-width :initarg :subview-width :initform nil :accessor subview-width-of)) (:default-initargs :item-type 'label :items nil :default-tag "Item-")) (defclass data-display-list (data-extract-mixin display-list) () (:default-initargs :labels #'identifier-name :initform-fn #'get-dataset-init :item-type 'data-label :title-type 'label )) (defclass case-display-list (data-display-list) () (:default-initargs :default-tag "Case-" )) (defclass batch-display-list (data-display-list) ((batches :initform nil :initarg :batches :accessor batches-of) (by-vars :initform nil :initarg :by :accessor by-vars-of) ) (:default-initargs :item-type 'group-label :by :prompt :initform-fn #'get-batch-inits :default-tag "Group-")) (defclass variate-display-list (data-display-list) () (:default-initargs :labels #'variate-string-of :initform-fn #'get-dataset-init :default-tag "Var-")) (defmethod default-display-items-of ((self display-list)) nil) (defmethod default-display-items-of ((self case-display-list)) (cases-of self)) (defmethod default-display-items-of ((self variate-display-list)) (variates-of self)) (defgeneric draw-region-height (display-list) ) (defgeneric draw-region-width (display-list) ) (defmethod display-length-of ((self display-list)) (length (subviews-of self))) (defmethod draw-region-width ((self display-list)) (+ (* 2 (display-list-border-of self)) (sub-view-width self))) (defmethod draw-region-height ((self display-list)) (+ (* 2 (display-list-border-of self)) (* (sub-view-height self) (display-length-of self)))) (defmethod make-draw-viewport ((self display-list) &optional title) (let* ((w (draw-region-width self)) (h (draw-region-height self)) (topi 40) (righti 5) (scroll 15) (win (make-view-window :title title :left (max 0 (- (wb:screen-width) righti scroll w)) :bottom (max 0 (- (wb:screen-height) topi scroll h)) :right (- (wb:screen-width) righti) :top (- (wb:screen-height) topi)))) (make-viewport win))) (defmethod sub-view-height ((self display-list) &optional sub) (or (subview-height-of self) (let () (if (null sub) (setq sub (car (subviews-of self)))) (if (and sub (typep sub 'label)) (+ (* 2 (wb::canvas-font-leading (draw-style sub :font ))) (wb:canvas-font-height (draw-style sub :font ))) 20)))) (defmethod sub-view-width ((self display-list) &optional sub) (or (subview-width-of self) (let () (if (and sub (typep sub 'label)) (wb:canvas-string-width nil (get-text sub) :font (draw-style sub :font )) (let ((w (loop for s in (subviews-of self) when (and s (typep s 'label)) maximize (wb:canvas-string-width nil (get-text s) :font (draw-style s :font ))))) (if (or (null w) (zerop w)) 150 w)))))) (defmethod compute-sub-viewports ((self display-list) &optional viewport new-start) (declare (ignore subviews)) (if (and new-start (listp new-start)) (setq new-start (if (numberp (first new-start)) (first new-start) (second new-start)))) (loop with border = (display-list-border-of self) with subs = (subviews-of self) for vp in (if viewport (list viewport) (viewports-of self)) for w = (window-of vp) for start = (or new-start (view-start self :viewport vp)) do (multiple-value-bind (l r b tp) (bounds-of vp) (declare (ignorable b)) (incf l border) (decf r border) (decf tp border) #| (loop with y = tp for i from (- start 1) downto 0 for sub = (elt subs i) for sv-vp = (or (select-viewport sub vp) (make-viewport w)) for h = (sub-view-height self sub) do (setf (bounds-of sv-vp) (list l r y (+ h y))) (incf y h) (add-viewport sub sv-vp vp)) |# (loop with y = tp for i from (1- start) downto 0 for sub = (elt subs i) for sv-vp = (or (select-viewport sub vp) (make-viewport w)) for h = (sub-view-height self sub) do (setf (bounds-of sv-vp) (list l r y (+ y h) )) (incf y h) (add-viewport sub sv-vp vp)) (loop with y = tp for i from start below (display-length-of self) for sub = (elt subs i) for sv-vp = (or (select-viewport sub vp) (make-viewport w)) for h = (sub-view-height self sub) do (setf (bounds-of sv-vp) (list l r (- y h) y)) (decf y h) (add-viewport sub sv-vp vp))))) (defmethod construct-sub-views ((self display-list) &rest args &key items item-type subviews) (declare (ignore args)) (setq items (or items (default-display-items-of self))) (let* ((sub-view-args (subview-arg-list item-type 'label)) ) (setq sub-view-args (append sub-view-args (list :orientation :horizontal :justification :left))) (setf (subviews-of self) (or subviews (if (listp items) (loop for l in items collect (apply #'view :text l sub-view-args)) ))))) (defmethod construct-sub-views ((self data-display-list) &rest args &key items title labels item-type title-type default-tag ) (declare (ignore args)) (let* ( (sub-vo (or items (default-display-items-of self))) (title-string (if title (princ-to-string (or title (dataset-name (viewed-object-of self)) "Cases")))) (sub-view-args (subview-arg-list item-type 'data-label)) (get-label (cond ((and labels (listp labels)) #'(lambda(i) (nth i labels))) ((functionp labels) #'(lambda(i) #'(lambda(vo) (let ((l (funcall labels vo))) (or l (format nil "~A~S" default-tag i)))))) (t #'(lambda(i) (declare (ignore i)) labels))))) (setq sub-view-args (append sub-view-args (list :orientation :horizontal :justification :left))) (setf (subviews-of self) (if (and sub-vo (listp sub-vo)) (loop for vo in sub-vo for i upfrom 0 for l = (funcall get-label i) collect (apply #'view :text l :clip-label? t :data vo sub-view-args)) (if (listp labels) (loop for l in labels collect (apply #'view :text l sub-view-args)) ))) (if title (push (apply #'view :text title-string :type title-type :clip-label? t :data (viewed-object-of self) :draw? nil (disable-keyword sub-view-args :type)) (subviews-of self))))) (defmethod construct-sub-views ((self batch-display-list) &rest args &key batches by order-levels) (if (or by batches) (let (( subsets (remove nil (get-batches :by by :batches batches :dataset (dataset-of self) :cases (cases-of self) :order-levels order-levels)))) (apply #'call-next-method self :items (remove nil subsets) args)) (apply #'call-next-method self args))) (defmethod max-view-start ((self display-list) &key viewport axis) (declare (ignore axis)) (if viewport (let ((len (loop for s in (subviews-of self) for vp = (select-viewport s viewport) count (active-viewport-p vp ) ))) (- (display-length-of self) len)) (display-length-of self))) (defmethod view-start ((self display-list) &key viewport axis) (declare (ignore axis)) (if viewport (loop for s in (subviews-of self) for vp = (select-viewport s viewport) until (or (null vp) (not (active-viewport-p vp ))) count (active-viewport-p vp ) )) 0) (defvar *display-items-limit* 6 "When the number of items in a display list exceeds~ this value, the default is to add a right scroller~ to the display") (defun display-list (&rest args &key (display-type 'display-list) (scrollable? :default) (draw? nil) &allow-other-keys) (let (( display (apply #'make-instance display-type :draw? nil args))) (if (eq scrollable? :default) (setq scrollable? (> (display-length-of display) *display-items-limit*))) (if scrollable? (setq display (scrolling-display :draw? draw? :data (viewed-object-of display) :bottom-scroller nil :display display)) (if draw? (draw-view display))) display)) (defun case-display-list (&rest args) (apply #'display-list :display-type 'case-display-list args)) (defun variate-display-list(&rest args) (apply #'display-list :display-type 'variate-display-list args)) (defun batch-display-list(&rest args) (apply #'display-list :display-type 'batch-display-list args))
11,859
Common Lisp
.l
264
31.734848
133
0.518211
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3acebdf20b51855b07868325f95a83a6712e393d5a19cc1fa0461f8195123504
33,226
[ -1 ]
33,227
draw-style-mixins.lsp
rwoldford_Quail/source/views/views-general/draw-style-mixins.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; draw-style-mixins.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(draw-style-mixin single-draw-style-mixin multiple-draw-style-mixin construct-new-style-p style-keys-of drawing-style-of set-drawing-style set-highlight-style style-proportions all-highlight? any-highlight?))) ;;;---------------------------------------------------------------------------------- (defclass draw-style-mixin () ((style-keys :initform nil :allocation :class :accessor style-keys-of) (drawing-style :initarg :drawing-style :initform nil :documentation "an alist specifying how view is to be drawn") )) (defclass single-draw-style-mixin (draw-style-mixin) ()) (defclass multiple-draw-style-mixin (draw-style-mixin) ((drawing-style :initarg :drawing-style :initform nil :accessor drawing-styles-of))) (defgeneric drawing-style-of (draw-style-mixin &key &allow-other-keys) (:documentation "Returns drawing style of self as an alist ")) (defgeneric set-drawing-style (draw-style-mixin &rest style-pairs &key &allow-other-keys) (:documentation "Sets draw-styles according to style pairs and redraws ")) (defgeneric set-highlight-style (view hi-val &rest args &key &allow-other-keys)) (defgeneric style-proportions (multiple-draw-style-mixin style-keys &optional args) (:documentation "Returns the proportions of self drawn with ~ each combination of values for styles in style-keys")) (defgeneric default-drawing-style (draw-style-mixin &key &allow-other-keys) (:documentation "Returns a default style for view")) (defgeneric init-drawing-style (draw-style-mixin &key &allow-other-keys) (:documentation "Called at view initialization to construct the drawing style")) (defgeneric check-styles (draw-style-mixin style-keys) (:documentation "Checks that view has correct styles and adds if necessary")) (defgeneric construct-new-style-p (draw-style-mixin) (:documentation "Tests if the drawing style needs to be reconstructed")) ;;;---------------------------------------------------------------------------------- (defmethod initialize-instance :after ((self draw-style-mixin) &rest keyword-pairs &key check-style? ) (let ((style-keys (style-keys-of self))) (if (construct-new-style-p self) (apply #'init-drawing-style self (find-pairs keyword-pairs style-keys)) (if check-style? (check-styles self (find-pairs keyword-pairs style-keys) ))))) (defmethod default-drawing-style ((self draw-style-mixin) &rest keyword-pairs &key (highlight? nil) (invisible? nil)) (apply #'make-drawing-style :highlight? highlight? :invisible? invisible? keyword-pairs)) (defmethod drawing-style-of ((self draw-style-mixin) &key) (slot-value self 'drawing-style)) (defmethod (setf drawing-style-of) (new-style (self draw-style-mixin) ) (setf (slot-value self 'drawing-style) new-style)) (defmethod init-drawing-style ((self single-draw-style-mixin) &rest keyword-pairs) (setf (drawing-style-of self) (apply #'default-drawing-style self keyword-pairs))) (defmethod construct-new-style-p ((self single-draw-style-mixin)) (not (drawing-style-p (drawing-style-of self)))) (defmethod check-styles ((self single-draw-style-mixin) style-keys) (let ((ds (drawing-style-of self))) (loop for style in style-keys by #'cddr for val in (cdr style-keys) by #'cddr unless (has-draw-style-p ds style) do (add-style ds style val)))) (defmethod drawing-styles-of ((self single-draw-style-mixin)) (list (drawing-style-of self))) (defmethod has-draw-style-p ((self single-draw-style-mixin) slot-name) (has-draw-style-p (drawing-style-of self) slot-name)) (defmethod element-draw-style ((self single-draw-style-mixin) viewed-obj-elt test ) (when (member viewed-obj-elt (list-viewed-elements self) :test test ) (drawing-style-of self))) (defmethod draw-style ((self single-draw-style-mixin) slot-name &key) (draw-style (drawing-style-of self) slot-name)) (defmethod set-draw-style :around ((self single-draw-style-mixin) (slot-name (eql :color)) (val (eql :prompt)) &key) (set-draw-style (drawing-style-of self) :color (wb::prompt-user-for-color))) (defmethod set-draw-style ((self single-draw-style-mixin) slot-name val &key) (set-draw-style (drawing-style-of self) slot-name val)) (defmethod copy-style-values ((view-1 single-draw-style-mixin) (view-2 single-draw-style-mixin)) (copy-style-values (drawing-style-of view-1) (drawing-style-of view-2))) (defmethod viewed-elt-test ((self draw-style-mixin)) *default-data-eq*) #| (defmethod set-drawing-style ((self single-draw-style-mixin) &key element styles test from elements) ;; accepts a single viewed object (when (or (null element) ;;(and from (member self (linked-views-of from))) (and from (member element (list-viewed-elements self) :test (or test (viewed-elt-test self)))) (and from (subsetp elements (list-viewed-elements self) :test (or test (viewed-elt-test self))))) (loop for style in styles by #'cddr for val in (cdr styles) by #'cddr do (set-draw-style self style val )) :set-style)) (defmethod set-highlight-style ((self single-draw-style-mixin) hi-val &key element test from not-from) ;; accepts a single viewed object (when (or (and (null element) (null not-from)) ;;(and from (member self (linked-views-of from)) ) from (member element (list-viewed-elements self) :test (or test (viewed-elt-test self))) (and not-from (not (if (typep not-from 'view) (or (eq not-from self) (member self (linked-views-of not-from))) (some #'(lambda(v) (or (eq v self) (member self (linked-views-of v)) )) not-from))))) (set-draw-style self :highlight? hi-val ) :set-style)) |# (defmethod set-drawing-style ((self single-draw-style-mixin) &key element styles test from elements) (declare (ignore from)) (when (or (and (null element) (null elements)) (and elements (intersection elements (list-viewed-elements self) :test (or test (viewed-elt-test self)))) (and element (member element (list-viewed-elements self) :test (or test (viewed-elt-test self))))) (loop for style in styles by #'cddr for val in (cdr styles) by #'cddr do (set-draw-style self style val )) :set-style)) (defmethod set-highlight-style ((self single-draw-style-mixin) hi-val &key element elements test from not-from) (declare (ignore from)) (when (or (and (null element) (null elements) (null not-from)) (and elements (intersection elements (list-viewed-elements self) :test (or test (viewed-elt-test self)))) (and element (member element (list-viewed-elements self) :test (or test (viewed-elt-test self)))) (and not-from (not (if (typep not-from 'view) (or (eq not-from self) (member self (linked-views-of not-from))) (some #'(lambda(v) (or (eq v self) (member self (linked-views-of v)) )) not-from))))) (set-draw-style self :highlight? hi-val ) :set-style)) ;;-------------------------------------------------------------------------------- (defmethod construct-new-style-p ((self multiple-draw-style-mixin)) (let ((ds (drawing-styles-of self)) ) (if (and ds (listp ds) (every #'drawing-style-p ds)) (let ((list-vo (list-viewed-elements self))) (not (= (length ds) (if list-vo (length list-vo) 1)))) t))) (defmethod has-draw-style-p ((self multiple-draw-style-mixin) slot-name) (loop for ds in (drawing-styles-of self) thereis (has-draw-style-p ds slot-name))) (defmethod summary-drawing-style ((self multiple-draw-style-mixin)) ;; could be done on a majority basis (let* ((all-styles (drawing-styles-of self)) (sty (copy-drawing-style (car all-styles))) (h-val (loop for s in all-styles thereis (draw-style s :highlight?))) (i-val (loop for s in all-styles thereis (draw-style s :invisible?)))) (set-draw-style sty :highlight? h-val) (set-draw-style sty :invisible? i-val) sty)) (defmethod drawing-style-of ((self multiple-draw-style-mixin) &key element (test (viewed-elt-test self))) ;; gets style corresponding to element ;; if the element does not have a corresponding ;; style use single (summary) drawing style (or (element-draw-style self element test) (summary-drawing-style self))) (defmethod init-drawing-style ((self multiple-draw-style-mixin) &rest keyword-pairs) ;; one draw style per element of viewed-elements ;; where draw-styles and element are matched by position (setf (drawing-styles-of self) (loop with list-vo = (list-viewed-elements self) repeat (if list-vo (length list-vo) 1) collect (apply #'default-drawing-style self keyword-pairs)))) (defmethod check-styles ((self multiple-draw-style-mixin) style-keys) (loop for ds in (drawing-styles-of self) do (loop for style in style-keys by #'cddr for val in (cdr style-keys) by #'cddr unless (has-draw-style-p ds style) do (add-style ds style val)))) (defmethod element-draw-style ((self multiple-draw-style-mixin) viewed-obj-elt test ) (let ((p (if viewed-obj-elt (position viewed-obj-elt (list-viewed-elements self) :test test)))) (if p (elt (drawing-styles-of self) p)))) (defmethod element-draw-styles ((self multiple-draw-style-mixin) viewed-obj-elt test ) (if viewed-obj-elt (loop for ve in (list-viewed-elements self) for d in (drawing-styles-of self) when (funcall test ve viewed-obj-elt) collect d))) (defmethod draw-style ((self multiple-draw-style-mixin) slot-name &key element) ;; gets style corresponding to element ;; if the element does not have a corresponding ;; style use single (summary) drawing style (draw-style (drawing-style-of self :element element) slot-name)) (defmethod draw-style ((self multiple-draw-style-mixin) ( slot-name (eql :invisible?)) &key element) ;; multi-style view draw method should handle invisible (if (null element) nil (call-next-method))) (defmethod set-draw-style ((self multiple-draw-style-mixin) slot-name val &key element (test (viewed-elt-test self))) ;; sets style corresponding to element ;; if the element is nil set all styles (if (null element) (loop for ds in (drawing-styles-of self) do (set-draw-style ds slot-name val)) (let ((ds-vo (element-draw-style self element test))) (if ds-vo (set-draw-style ds-vo slot-name val))))) (defmethod set-draw-style :around ((self multiple-draw-style-mixin) (slot-name (eql :color)) (val (eql :prompt)) &key element (test (viewed-elt-test self))) (let ((new-colour (wb::prompt-user-for-color))) (set-draw-style self :color new-colour :element element :test test))) #| (defmethod set-drawing-style ((self multiple-draw-style-mixin) &key element styles from (test (viewed-elt-test self))) (let ((changes? nil)) (cond ((and (null element) (null from)) (setq changes? :set-style) (loop for style in styles by #'cddr for val in (cdr styles) by #'cddr do (set-draw-style self style val ))) ((and element (not from)) (loop for ds-vo in (element-draw-styles self element test) do (setq changes? :set-style) (loop for style in styles by #'cddr for val in (cdr styles) by #'cddr do (set-draw-style ds-vo style val )))) (from (loop with from-elts = (or element (list-viewed-elements from)) for elt in (list-viewed-elements self) for ds-vo in (drawing-styles-of self) when (member-if #'(lambda(x) (funcall test x elt)) from-elts) do (setq changes? :set-style) (loop for style in styles by #'cddr for val in (cdr styles) by #'cddr do (set-draw-style ds-vo style val ))) (when (and (null changes?) (null element)) (setq changes? :set-style) (loop for style in styles by #'cddr for val in (cdr styles) by #'cddr do (set-draw-style self style val )))) (t nil)) changes?)) (defmethod set-highlight-style ((self multiple-draw-style-mixin) hi-val &key element from not-from (test (viewed-elt-test self))) ;; accepts a single viewed object (let ((changes? nil)) (cond ((and (null element) (null from) (null not-from) ) (setq changes? :set-style) (set-draw-style self :highlight? hi-val )) ((and element (not from)) (loop for ds-vo in (element-draw-styles self element test) do (setq changes? :set-style) (set-draw-style ds-vo :highlight? hi-val ))) (from (loop with from-elts = (or element (list-viewed-elements from)) for elt in (list-viewed-elements self) for ds-vo in (drawing-styles-of self) when (member-if #'(lambda(x) (funcall test x elt)) from-elts) do (setq changes? :set-style) (set-draw-style ds-vo :highlight? hi-val )) (when (and (null changes?) (null element)) (setq changes? :set-style) (set-draw-style self :highlight? hi-val )) ) ((and not-from (typep not-from 'view) (not (eq not-from self))) (if (not (member self (linked-views-of not-from))) (progn (setq changes? :set-style) (set-draw-style self :highlight? hi-val )) (loop with from-elts = (list-viewed-elements not-from) with not-all? = nil with test = (link-table-test-of (link-table-of self)) for element in (list-viewed-elements self) for ds-vo in (drawing-styles-of self) if (member-if #'(lambda(x) (funcall test x element)) from-elts) do (setq not-all? t) else collect ds-vo into change-ds finally (when not-all? (setq changes? :set-style) (loop for d in change-ds do (set-draw-style d :highlight? hi-val )))))) ((and not-from (listp not-from) (not (member self not-from))) (if (not (some #'(lambda(x) (member self (linked-views-of x))) not-from)) (progn (setq changes? :set-style) (set-draw-style self :highlight? hi-val )) (loop with from-elts = (loop for v in not-from append (list-viewed-elements v)) with not-all? = nil with test = (link-table-test-of (link-table-of self)) for element in (list-viewed-elements self) for ds-vo in (drawing-styles-of self) if (member-if #'(lambda(x) (funcall test x element)) from-elts) do (setq not-all? t) else collect ds-vo into change-ds finally (when not-all? (setq changes? :set-style) (loop for d in change-ds do (set-draw-style d :highlight? hi-val )))))) (t nil)) changes?)) |# (defmethod set-drawing-style ((self multiple-draw-style-mixin) &key element styles from elements highlit? (test (viewed-elt-test self))) (let ((changes? nil)) (cond ((and (null element) (null from) (null elements)) (setq changes? :set-style) (if (or (eq t highlit?) (and highlit? (any-highlight? self))) (loop for d in (drawing-styles-of self) when (draw-style d :highlight?) do (loop for style in styles by #'cddr for val in (cdr styles) by #'cddr do (set-draw-style d style val ))) (loop for style in styles by #'cddr for val in (cdr styles) by #'cddr do (set-draw-style self style val )))) ((or elements from) (loop with from-elts = (or elements (list-viewed-elements from)) for elt in (list-viewed-elements self) for ds-vo in (drawing-styles-of self) when (member-if #'(lambda(x) (funcall test x elt)) from-elts) do (setq changes? :set-style) (loop for style in styles by #'cddr for val in (cdr styles) by #'cddr do (set-draw-style ds-vo style val ))) (when (and (null changes?) (null elements)) (setq changes? :set-style) (loop for style in styles by #'cddr for val in (cdr styles) by #'cddr do (set-draw-style self style val )))) (element (loop for ds-vo in (element-draw-styles self element test) do (setq changes? :set-style) (loop for style in styles by #'cddr for val in (cdr styles) by #'cddr do (set-draw-style ds-vo style val )))) (t nil)) changes?)) (defmethod set-highlight-style ((self multiple-draw-style-mixin) hi-val &key element from not-from elements (test (viewed-elt-test self))) ;; accepts a single viewed object (let ((changes? nil)) (cond ((and (null element) (null from) (null not-from) (null elements) ) (setq changes? :set-style) (set-draw-style self :highlight? hi-val )) ((or elements from) (loop with from-elts = (or elements (list-viewed-elements from)) for elt in (list-viewed-elements self) for ds-vo in (drawing-styles-of self) when (member-if #'(lambda(x) (funcall test x elt)) from-elts) do (setq changes? :set-style) (set-draw-style ds-vo :highlight? hi-val )) (when (and (null changes?) (null elements)) (setq changes? :set-style) (set-draw-style self :highlight? hi-val )) ) (element (loop for ds-vo in (element-draw-styles self element test) do (setq changes? :set-style) (set-draw-style ds-vo :highlight? hi-val ))) ((and not-from (typep not-from 'view) (not (eq not-from self))) (if (not (member self (linked-views-of not-from))) (progn (setq changes? :set-style) (set-draw-style self :highlight? hi-val )) (loop with from-elts = (list-viewed-elements not-from) with not-all? = nil with test = (link-table-test-of (link-table-of self)) for element in (list-viewed-elements self) for ds-vo in (drawing-styles-of self) if (member-if #'(lambda(x) (funcall test x element)) from-elts) do (setq not-all? t) else collect ds-vo into change-ds finally (when not-all? (setq changes? :set-style) (loop for d in change-ds do (set-draw-style d :highlight? hi-val )))))) ((and not-from (listp not-from) (not (member self not-from))) (if (not (some #'(lambda(x) (member self (linked-views-of x))) not-from)) (progn (setq changes? :set-style) (set-draw-style self :highlight? hi-val )) (loop with from-elts = (loop for v in not-from append (list-viewed-elements v)) with not-all? = nil with test = (link-table-test-of (link-table-of self)) for element in (list-viewed-elements self) for ds-vo in (drawing-styles-of self) if (member-if #'(lambda(x) (funcall test x element)) from-elts) do (setq not-all? t) else collect ds-vo into change-ds finally (when not-all? (setq changes? :set-style) (loop for d in change-ds do (set-draw-style d :highlight? hi-val )))))) (t nil)) changes?)) (defmethod copy-style-values ((view-1 multiple-draw-style-mixin) (view-2 multiple-draw-style-mixin)) (loop for ds1 in (drawing-styles-of view-1) for ds2 in (drawing-styles-of view-2) do (copy-style-values ds1 ds2))) ;;------------------------------------------------------------------------------- (defmethod set-drawing-style :around ((self draw-style-mixin) &rest style-pairs &key (draw? t) (erase? :default) styles) (let* ((style-args (or styles (find-styles self style-pairs))) (hilite-only? (and ;;(null element) (null from) (= (length style-args) 2) (eq :highlight? (car style-args)))) result) (when (and (eq erase? :default) (or (member :width style-args) (member :size style-args))) (erase-view self) (setq erase? nil)) (setq result (apply #'call-next-method self :styles style-args style-pairs)) (when (and result style-args draw?) (unless (or hilite-only? (null style-args)) (if erase? (erase-view self))) (if hilite-only? (let ((hi-val (second style-args))) (update-highlight self hi-val)) (let ((pos (position :invisible? style-args))) (unless (and pos (draw-style self :invisible? )) (if (viewports-of self) (optional-cache (draw-view self ))) ) ))))) (defmethod set-highlight-style :around ((self draw-style-mixin) hi-val &rest args &key (draw? t) ) (if (and (apply #'call-next-method self hi-val args) draw?) (update-highlight self hi-val))) (defmethod update-highlight ((self draw-style-mixin) style-val) (if (null style-val) ; bug in macl case, it ignores nil clause? (optional-cache (downlight-view self)) (case style-val (:toggle (if (draw-style self :highlight?) (optional-cache (highlight-view self)) (optional-cache (downlight-view self)))) (t (optional-cache (highlight-view self)))))) (defmethod find-styles ((self draw-style-mixin) style-pairs) (loop with result for s in style-pairs by #'cddr for val in (cdr style-pairs) by #'cddr when (has-draw-style-p self s) do (push val result) (push s result) finally (return result))) ;;-------------------------------------------------------------------------------- ;; extracting proportions from mutiple-draw-style-mixin for different ;; style combinations (defmethod style-values ((self multiple-draw-style-mixin) style) ;; extracts all the values for style in drawing-style of self (loop with stl-vals for ds in (drawing-styles-of self) do (pushnew (draw-style ds style) stl-vals) finally (return stl-vals))) (defmethod order-style-values ((self multiple-draw-style-mixin) style) (order-style-values (style-values self style) style)) (defmethod order-style-values ( (vals list) style) (declare (ignore style)) (if (and (= 2 (length vals)) (member nil vals) (member t vals)) (list t nil) vals)) (defmethod order-style-values ( (vals list) (style (eql :color) )) (if (or (some #'wb:colorp vals) (every #'null vals)) (wb:order-colors (remove-duplicates vals :test #'wb:eq-colors)) (wb:order-patterns (remove-duplicates vals :test #'wb:eq-patterns)))) (defun sty-cross-prod (a b) ;; a and b are (possibly null) lists) ;; return the set cross product (cond ((or (null a) (null b)) (setq a (or a b)) (loop for ai in a collect (if (and ai (listp ai)) ai (list ai)))) (t (loop for ai in a for ai-list = (if (and ai (listp ai)) ai (list ai)) nconc (loop for bi in b collect (if (and bi (listp bi)) (append ai-list bi) (append ai-list (list bi)))))))) (defun styles-match-p (draw-stl keys vals) ;; returns t if draw-stl has key-value pairs eq to ;; the ith keys -- vals, for each i (loop for k in keys for v in vals always (eq (draw-style draw-stl k) v))) (defmethod style-proportions ((self multiple-draw-style-mixin) style-keys &optional weights) ;; returns the proportions of self drawn with ;; combination of styles (if (null style-keys) (list '(t) '(1.0)) (let (style-combinations style-counts) (unless (listp style-keys) (setq style-keys (list style-keys))) (loop for sk in style-keys for sk-vals = (order-style-values self sk) do (setq style-combinations (sty-cross-prod style-combinations sk-vals))) (setq style-counts (make-list (length style-combinations) :initial-element 0)) (loop for d in (drawing-styles-of self) for i upfrom 0 do (loop for style-vals in style-combinations for s-count on style-counts do (if (styles-match-p d style-keys style-vals) (incf (car s-count) (if weights (nth i weights) 1))))) (loop with n = (reduce #'+ style-counts) for c in style-counts for sc in style-combinations unless (zerop c) collect (/ c n) into sty-counts and collect sc into sty-combinations finally (return (list sty-combinations sty-counts)))))) (defmethod style-proportions-in-order ((self multiple-draw-style-mixin) style-keys &optional weights) (flet ((test(s1 s2) (loop for k in style-keys always (eq (draw-style s1 k) (draw-style s2 k))))) (let* ((styles (drawing-styles-of self)) (n (if weights (reduce #'+ weights) (length styles)))) (loop with combs = (list (first styles)) with counts = (if weights (list (car weights)) (list 1)) for s in (cdr styles) for i upfrom 1 for merge? = (test s (first combs)) unless merge? do (push s combs) (push (if weights (nth i weights) 1) counts) when merge? do (incf (car counts) (if weights (nth i weights) 1)) finally (return (list (loop for comb in (reverse combs) collect (loop for k in style-keys collect (draw-style comb k))) (mapcar #'(lambda(x) (/ x n)) (reverse counts)))))))) (defmethod update-instance-for-different-class :after ((old single-draw-style-mixin) (new multiple-draw-style-mixin) &rest initargs) (declare (ignore initargs)) (if (slot-boundp old 'drawing-style) (unless (typep old 'multiple-draw-style-mixin) (let ((style-args (loop for (a . b) in (drawing-style-of old) collect a collect b))) (setf (drawing-style-of new) (loop with list-vo = (list-viewed-elements old) repeat (if list-vo (length list-vo) 1) collect (apply #'default-drawing-style new style-args))))))) (defmethod update-instance-for-different-class :after ((old multiple-draw-style-mixin) (new single-draw-style-mixin) &rest initargs) (declare (ignore initargs)) (if (slot-boundp old 'drawing-style) (unless (typep new 'multiple-draw-style-mixin) (setf (drawing-style-of new) (drawing-style-of old))) )) (defmethod update-instance-for-different-class :around ((old draw-style-mixin) (new draw-style-mixin) &rest initargs) (declare (ignore initargs)) (call-next-method) (if (slot-boundp new 'drawing-style) (let* ((style-keys (style-keys-of new)) view style-defaults) (unless (loop for key in style-keys always (has-draw-style-p new key)) (setq view (view :type (class-name (class-of new)))) (setq style-defaults (loop for (a . b) in (drawing-style-of view) collect a collect b)) (check-styles new (find-pairs style-defaults style-keys)))))) (defgeneric any-highlight? (view) (:documentation "Returns t if any part of the view is highlit")) (defmethod any-highlight? ((self single-draw-style-mixin)) (draw-style self :highlight?)) (defmethod any-highlight? ((self multiple-draw-style-mixin)) (loop for d in (drawing-styles-of self) thereis (draw-style d :highlight?))) (defgeneric all-highlight? (view) (:documentation "Returns t if all parts of the view are highlit")) (defmethod all-highlight? ((self single-draw-style-mixin)) (draw-style self :highlight?)) (defmethod all-highlight? ((self multiple-draw-style-mixin)) (loop for d in (drawing-styles-of self) always (draw-style d :highlight?))) (defmethod highlight-value ((self single-draw-style-mixin) &optional toggle) (if toggle (not (draw-style self :highlight?)) (draw-style self :highlight?) )) (defmethod highlight-value ((self multiple-draw-style-mixin) &optional toggle) (if toggle (loop for d in (drawing-styles-of self) collect (not (draw-style d :highlight?))) (loop for d in (drawing-styles-of self) collect (draw-style d :highlight?)))) (defgeneric set-highlight-style-on(self &rest args &key &allow-other-keys ) ) #| (defgeneric highlit-viewed-elements(self &key status) ) (defmethod highlit-viewed-elements ((self single-draw-style-mixin) &key (status t )) (if (eq (draw-style self :highlight?) status) (list-viewed-elements self))) (defmethod highlit-viewed-elements ((self multiple-draw-style-mixin) &key (status t ) ) (loop for d in (drawing-styles-of self) for v in (list-viewed-elements self) when (eq status (draw-style d :highlight?)) collect v)) |# (defun active-viewports-p(view) (loop for v in (viewports-of view) thereis (active-viewport-p v)))
34,255
Common Lisp
.l
673
37.734027
134
0.55729
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
769764a5e985a92a898075694c2a2fa313c41f9c18b36e76ea0802583b816d81
33,227
[ -1 ]
33,228
layer.lsp
rwoldford_Quail/source/views/views-general/layer.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; layer.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(layer-view layer-subview layer-selected-view make-layer-view layer-link-view compute-default-clip-region compute-ignore-x compute-ignore-y add-line add-lines add-simple-lines add-simple-smooth add-smooth add-fitted-line add-point-cloud add-function))) (defgeneric layer-link-view (view on-view &key parent &allow-other-keys) (:documentation "Places layer on view and links ")) (defgeneric layer-subview (parent view on &key &allow-other-keys) (:documentation "Places view on top of view on .~ Adds view as subview of parent")) (defgeneric layer-view (view layer &key viewport &allow-other-keys) (:documentation "Places layer on view in viewport ")) (defgeneric make-layer-view (view layer &rest args) (:documentation "Make a view pf type layer to be layered on view")) (defgeneric layer-selected-view (view &key viewport &allow-other-keys) (:documentation "Places the selected view on view in viewport ")) (defgeneric compute-default-clip-region (view on-view) (:documentation "Computes the clip region used~ when on-view is layered on top of view")) (defgeneric compute-ignore-x (view) (:documentation "Computes whether the x-bounds are to be ~ left unchanged when view is layered")) (defgeneric compute-ignore-y (view) (:documentation "Computes whether the y-bounds are to be ~ left unchanged when view is layered")) (defgeneric add-line (view &key &allow-other-keys ) (:documentation "Makes line and layers on a subview")) (defgeneric add-function (view &key &allow-other-keys) (:documentation "Makes function-view and layers on a subview")) (defgeneric add-point-cloud (view &key &allow-other-keys) (:documentation "Makes point-cloud and layers on a subview")) (defgeneric add-fitted-line (view &key &allow-other-keys ) (:documentation "Makes fitted line and layers on a subview")) (defgeneric add-lines (view &key &allow-other-keys) (:documentation "Makes lines view and layers on a subview")) (defgeneric add-simple-lines (view &key &allow-other-keys) (:documentation "Makes simple-lines view and layers on a subview")) (defgeneric add-smooth (view &key &allow-other-keys) (:documentation "Makes smoothed-lines view and layers on a subview")) (defgeneric add-simple-smooth (view &key &allow-other-keys) (:documentation "Makes smoothed-simple-lines view and layers on a subview")) ;;---------------------------------------------------------------------- (defmethod layer-view ((self view ) (layer view) &rest arg &key viewport ) (loop for vp in (if viewport (list viewport) (viewports-of self)) for parent = (find-parent self :viewport vp ) do (if (and parent (legal-subview-p parent layer)) (apply #'layer-subview parent layer self arg) (apply #'layer-link-view layer self :parent vp arg) ) (when (member self *selected-views*) (remove-view self :viewport vp))) (when (member self *selected-views*) (deselect-view self)) layer) (defmethod layer-view ((self view) (layer symbol) &rest args &key viewport ) (let ((new (apply #'make-layer-view self layer args))) (apply #'layer-view self new :viewport viewport args))) (defmethod make-layer-view ((self view) (layer symbol) &rest args) (apply #'view :type layer :draw? nil args)) (defmethod layer-subview ((self view) (view view ) (on view ) &rest arg ) (let ((locn (select-sub-view-locn self on))) (if (null locn) (quail-error "~S is not a subview of ~S" on self)) (when (legal-subview-p self view) (place-subview self view (make-region locn)) (apply #'layer-link-view view on :parent self arg) ) view)) (defmethod layer-subview ((self view) (layer symbol) (on view ) &rest args ) (let ((new (apply #'make-layer-view on layer args))) (apply #'layer-subview self new on args) new)) (defmethod layer-subview :around ((self view) (view view) (on view ) &rest arg ) (declare (ignore arg)) (call-next-method) (when (member on *selected-views*) (deselect-view on) (remove-subview self on ))) (defmethod compute-default-clip-region ((view view) (on-view view)) (bounding-region-of on-view)) (defmethod compute-ignore-x ((view view) ) (not (linkable-bounds-x-p view))) (defmethod compute-ignore-y ((view view) ) (not (linkable-bounds-y-p view))) (defmethod layer-link-view ((view linkable-bounds-mixin ) (on-view linkable-bounds-mixin ) &key parent (delta-region nil) (draw? t) (clip-region :default) (ignore-x? :default) (ignore-y? :default)) "Places view on top of view on .~ By default the coordinate system of added view ~ is the same as that of on-view .~ If delta-region is non-nil it specifies the shift ~ from the view coords to those of added view.~ If delta-region is t it is computed using the current ~ bounding regions. All views are clipped to clip-region, ~ which should be in the coords of view on.~ If clip-region is :max the bounding regions of views ~ with related coordinate systems are maximized .~ If clip-region is :default, a reasonable region ~ is computed from on-view and view. ~ Typically, it ~ will be set to the bounding region of the on view.~ However if view is the only one of view and on-view ~ which is a d-view, then its bounding region ~ is used as the d-view." (if (eq clip-region :default) (setq clip-region (compute-default-clip-region view on-view))) (if (eq ignore-x? :default) (setq ignore-x? (compute-ignore-x view))) (if (eq ignore-y? :default) (setq ignore-y? (compute-ignore-y view))) (let* ( (br-v (bounding-region-of view)) (br-ov (bounding-region-of on-view)) (draw-new-only? (or (eq clip-region (bounding-region-of on-view)) (and (eq clip-region :max) (eq t delta-region)) ))) (change-bounding-region view br-ov :pretty? nil :ignore-x? ignore-x? :ignore-y? ignore-y? :draw? nil) (unless ignore-x? (link-view-bounds (union (link-bounds-x-of on-view) (link-bounds-x-of view)) :x)) (unless ignore-y? (link-view-bounds (union (link-bounds-y-of on-view) (link-bounds-y-of view)) :y)) (if draw-new-only? (if (typep parent 'view) (remap-sub-to-viewports parent view :erase? nil :draw? draw?) (add-view-to-window (window-of parent) view :draw? draw? :viewport (copy-region parent))) (let () (setq clip-region (if (region-p clip-region) clip-region (maximize-regions br-ov br-v))) (if (typep parent 'view) (remap-sub-to-viewports parent view :erase? nil :draw? nil) (add-view-to-window (window-of parent) view :draw? nil :viewport (copy-region parent))) (change-bounding-region on-view (or clip-region (bounding-region-of on-view)) :draw? draw? :pretty? nil :ignore-x? ignore-x? :ignore-y? ignore-y?) )) )) (defmethod add-line ((self view) &rest keyword-args ) (apply #'layer-view self 'line keyword-args)) (defmethod add-line-segment ((self view) &rest keyword-args ) (apply #'layer-view self 'line-segment keyword-args)) (defmethod add-function ((self view) &rest keyword-args ) (apply #'layer-view self 'function-view keyword-args)) (defmethod add-fitted-line ((self view) &rest keyword-args ) (apply #'layer-view self 'fitted-line keyword-args)) (defmethod add-lines ((self view) &rest keyword-args ) (apply #'layer-view self 'lines keyword-args)) (defmethod add-simple-lines ((self view) &rest keyword-args) (apply #'layer-view self 'simple-lines keyword-args)) (defmethod add-smooth ((self view) &rest keyword-args) (apply #'layer-view self 'smooth keyword-args)) (defmethod add-simple-smooth ((self view) &rest keyword-args) (apply #'layer-view self 'simple-smooth keyword-args)) (defmethod add-point-cloud ((self view) &rest keyword-args) (apply #'layer-view self '2d-point-cloud keyword-args))
9,999
Common Lisp
.l
209
37.799043
111
0.582969
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ce30c0d442a3eef4f7f8d92898b6d02564010a1c8010342349f194793d452fd5
33,228
[ -1 ]
33,229
view-window.lsp
rwoldford_Quail/source/views/views-general/view-window.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; view-window.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for ;;; interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(view-window system-view-window-items make-view-window region-of viewports-and-views-of add-view-to-window remove-view which-window which-view which-toplevel-view drag-region create-region-with-mouse *current-dataset* ))) (defclass view-window (wb:canvas) ((region :accessor region-of :initform (make-region))) ) (defgeneric viewports-and-views-of (view-window) (:documentation "The views displayed in this view-window and their viewports. ~ A list of the viewports and views.")) (defgeneric add-view-to-window (w v &key draw? viewport) (:documentation " adds a view to view-window in position viewport.~ If viewport is not provided, a viewport on w is created ~ occupying all of w")) (defgeneric remove-view-from-window (view-window &key view viewport) (:documentation "The view view and the view drawn at viewport are removed from view-window")) (defgeneric which-view (view-window &optional location) (:documentation "Returns the view, its viewport, its parent, and the parent's viewport ~ at location and the distance as multiple values.")) (defgeneric which-toplevel-view (view-window &optional location) (:documentation " Returns the top-level view and its viewport ~ at location as multiple values.")) (defvar *current-dataset* nil) ;;;------------------------------------------------------------------------------------- ;;; ;;; Hook the viewports-and-views-of to the display slot of the canvas ;;; (defmethod viewports-and-views-of ((c view-window)) (wb:display-of c)) (defmethod (setf viewports-and-views-of) ( new-value (c view-window) ) (setf (wb:display-of c) new-value)) ;;;-------------------------------------------------------------------------------------- (defmethod set-bounds ((w view-window)) (multiple-value-bind (l r b tp) (wb:canvas-bounds w) (setf (bounds-of (region-of w)) (list l r b tp)))) ;;; 2 added forms 27SEP2024 to allow for mcclim's defining things in window-basics, and its definition ;;; of a region, while set-bounds is in views, with its separate defintion of a region #+:sbcl-linux(defun wb-to-vw (wb-region) "Input: a window-basics region such as #(10 20 30 40) Output: a matching views region #(REGION 10 20 30 40)" (vector 'region (svref wb-region 0) (svref wb-region 1) (svref wb-region 2) (svref wb-region 3))) #+:sbcl-linux(defmethod set-bounds ((w wb::color-canvas)) (multiple-value-bind (l r b tp) (wb::canvas-bounds w) (setf (bounds-of (wb-to-vw (wb::region-of w))) (list l r b tp)))) ;;;======================================================================== #| (defmethod add-view-to-window ((w view-window) v &key (draw? t) (viewport (make-viewport w 0 1 0 1))) ;; adds a VIEW to WINDOW in position viewport (unless (find-if #'(lambda (elt) (or (eql (car elt) viewport) (eql (cdr elt) v))) (viewports-and-views-of w)) (setf (window-of viewport) w) (map-to-viewport v viewport) (if draw? (draw-view v :viewport viewport )) (setf (viewports-and-views-of w) (acons viewport v (viewports-and-views-of w))) )) |# ;;; remove the unless 6-6-95. No particular reason, just... why not. (defmethod add-view-to-window ((w view-window) v &key (draw? t) (viewport (make-viewport w 0 1 0 1))) ;; adds a VIEW to WINDOW in position viewport (setf (window-of viewport) w) (map-to-viewport v viewport) (if draw? (draw-view v :viewport viewport )) (setf (viewports-and-views-of w) (acons viewport v (viewports-and-views-of w))) ) ;;;----------------------------------------------------------------------------------- (defun *view-left-button-fn* (canvas mouse-pos) (let ((click-pos (view-position mouse-pos))) (multiple-value-bind (view vp ) (which-view canvas click-pos) (when view (left-button-fn view :viewport vp :position click-pos))))) (defun *view-shift-left-button-fn* (canvas mouse-pos) (let ((click-pos (view-position mouse-pos))) (multiple-value-bind (view vp ) (which-view canvas click-pos) (when view (shift-left-button-fn view :viewport vp :position click-pos))))) (defun *view-ctrl-left-button-fn* (canvas mouse-pos) (let ((click-pos (view-position mouse-pos))) (multiple-value-bind (view vp ) (which-view canvas click-pos) (when view (ctrl-left-button-fn view :viewport vp :position click-pos ))))) (defun *view-middle-button-fn* (canvas mouse-pos) (let ((click-pos (view-position mouse-pos))) (multiple-value-bind (view vp ) (which-view canvas click-pos) (when view (middle-button-fn view :viewport vp :position click-pos))))) (defun *view-shift-middle-button-fn* (canvas mouse-pos) (let ((click-pos (view-position mouse-pos))) (multiple-value-bind (view vp ) (which-view canvas click-pos) (when view (shift-middle-button-fn view :viewport vp :position click-pos))))) (defun *view-ctrl-middle-button-fn* (canvas mouse-pos) (let ((click-pos (view-position mouse-pos))) (multiple-value-bind (view vp ) (which-view canvas click-pos) (when view (ctrl-middle-button-fn view :viewport vp :position click-pos))))) (defun *view-right-button-fn* (canvas mouse-pos) (let ((click-pos (view-position mouse-pos))) (multiple-value-bind (view vp ) (which-view canvas click-pos) (when view (right-button-fn view :viewport vp :position click-pos))))) (defun *view-shift-right-button-fn* (canvas mouse-pos) (let ((click-pos (view-position mouse-pos))) (multiple-value-bind (view vp ) (which-view canvas click-pos) (when view (shift-right-button-fn view :viewport vp :position click-pos))))) (defun *view-ctrl-right-button-fn* (canvas mouse-pos) (let ((click-pos (view-position mouse-pos))) (multiple-value-bind (view vp ) (which-view canvas click-pos) (when view (ctrl-right-button-fn view :viewport vp :position click-pos))))) ;;--------------------------------------------------------------------------------- (defun view-window-size-changed-p (view-window) (multiple-value-bind (l r b tp) (wb:canvas-bounds view-window) (not (and (= (- r l) (width-of (region-of view-window))) (= (- tp b) (height-of (region-of view-window))))))) (defun view-window-redisplay-fn (view-window) (wb:canvas-clear view-window) (when (view-window-size-changed-p view-window) (multiple-value-bind (l r b tp) (wb:canvas-bounds view-window) (let ((at (make-transform-for-regions (region-of view-window) (make-region l r b tp ) ))) (dolist (vp-v (viewports-and-views-of view-window)) (reshape-viewport (cdr vp-v) (car vp-v) :transform at :draw? nil ))) (set-bounds view-window))) (dolist (vp-v (viewports-and-views-of view-window)) (draw-view (cdr vp-v) :viewport (car vp-v)))) ;;---------------------------------------------------------------------------------------- ;;; ;;; NOTE: Both plot-menu-items and system-view-window-items are not ;;; to be used as title-menus on a canvas any more. ;;; Both of these menus are useful when no view-window (or canvas) ;;; exists; they are now part of a permanent quail-menubar. ;;; Indeed, system-view-window-items no longer exists. ;;; This makes the aclpc and the mcl version consistent. ;;; ... rwo May 9, 2000. (defun make-view-window (&rest canvas-keywords &key left right bottom top (background-color NIL) (view-window-class 'view-window) title (region NIL) &allow-other-keys) (setq title (if (stringp title) title "View Window")) (when (region-p region) (multiple-value-setq (left right bottom top) (bounds-of region))) (let ((canvas (if (and left right bottom top) (apply #'wb:make-canvas :canvas-class view-window-class :title title :left left :bottom bottom :width (1+ (- right left)) :background-color (or background-color wb::*default-canvas-background-color*);background-color :height (1+ (- top bottom)) canvas-keywords) (apply #'wb:make-canvas :canvas-class view-window-class :title title :background-color (or background-color wb::*default-canvas-background-color*);background-color canvas-keywords) ) ) ) (wb:set-left-button-fn canvas #'*view-left-button-fn*) (wb:set-middle-button-fn canvas #'*view-middle-button-fn*) (wb:set-right-button-fn canvas #'*view-right-button-fn*) (wb:set-ctrl-left-button-fn canvas #'*view-ctrl-left-button-fn*) (wb:set-ctrl-middle-button-fn canvas #'*view-ctrl-middle-button-fn*) (wb:set-ctrl-right-button-fn canvas #'*view-ctrl-right-button-fn*) (wb:set-shift-left-button-fn canvas #'*view-shift-left-button-fn*) (wb:set-shift-middle-button-fn canvas #'*view-shift-middle-button-fn*) (wb:set-shift-right-button-fn canvas #'*view-shift-right-button-fn*) (wb:set-redisplay-test canvas #'view-window-size-changed-p) (wb:set-redisplay-fn canvas #'view-window-redisplay-fn) (set-bounds canvas) canvas)) (defmethod remove-view-from-window ((self view-window) &key view viewport) (setf (viewports-and-views-of self) (remove-if #'(lambda (elt) (or (eql (car elt) viewport) (eql (cdr elt) view))) (viewports-and-views-of self)))) (defun which-window (location) (let* ((l (if (region-p location) (centre-of location ) location)) (canvas (wb:which-canvas (wb-position l)))) (if (and canvas (typep canvas 'view-window) (or (2d-position-p location) (contains-p (region-of canvas) (window-location location canvas )))) canvas))) (defmethod which-toplevel-view1 ((self view-window) &optional location) " Returns the top-level view and its viewport ~ at location as multiple values." (if (null location) (setq location (region-of self))) (let ((vpv (viewports-and-views-of self))) (if vpv (loop with view with viewport with dmin = 100000 for vp-v in vpv do (multiple-value-bind (a1 a2 a3 a4 d) (which-subview (cdr vp-v) (car vp-v) location) (declare (ignore a1 a2 a3 a4)) (when (and d (< d dmin) ) (setq view (cdr vp-v) viewport (car vp-v) dmin d))) finally (return (values view viewport)))))) (defmethod which-toplevel-view ((self view-window) &optional location) (which-toplevel-view1 self location)) (defmethod which-toplevel-view (location &optional ignore) ;; location is in screen coordinates (declare (ignore ignore)) (let ((view-window (if (region-p location) (which-window (centre-of location) ) (which-window location)))) (when view-window (setq location (window-location location view-window )) (which-toplevel-view1 view-window location)))) (defmethod which-view ((self view-window) &optional location) (declare (special *current-dataset*)) (if (null location) (setq location (region-of self))) (let ((vpv (viewports-and-views-of self) )) (if vpv (loop with closest for (vp . v) in vpv for r = (multiple-value-list (which-subview v vp location)) do (if (and (car r) (or (null closest) (< (fifth r) (fifth closest)) )) (setq closest r )) finally (setq *current-dataset* (if (and v (dataset-p (viewed-object-of v))) (viewed-object-of v))) (return (values-list closest)))))) (defmethod which-view (location &optional ignore) ;; location is in screen coordinates (declare (ignore ignore)) (let ((view-window (if (region-p location) (which-window (centre-of location) ) (which-window location)))) (when view-window (setq location (window-location location view-window )) (which-view view-window location)))) (defun screen-location (location &optional view-window) "Returns the position of location in screen coordinates rather ~ than window coordinates." (if (and (null view-window) (viewport-p location)) (setq view-window (window-of location))) (if (2d-position-p location) (make-2d-position (+ (2d-position-x location) (wb:screen-x view-window)) (+ (2d-position-y location ) (wb:screen-y view-window))) (shift-by (make-region location ) (wb:screen-x view-window) (wb:screen-y view-window)))) (defun window-location (location &optional view-window) "Returns the position of location in window coordinates rather ~ than screen coordinates." (if (and (null view-window) (viewport-p location)) (setq view-window (window-of location))) (if (2d-position-p location) (make-2d-position (+ (2d-position-x location ) (- (wb:screen-x view-window))) (+ (2d-position-y location) (- (wb:screen-y view-window)))) ;;else (let ((new-region (make-region location))) (shift-by new-region (- (wb:screen-x view-window)) (- (wb:screen-y view-window))) (if (viewport-p location) (make-viewport view-window new-region) new-region)))) (defun drag-region (region &key limit window (axis :both) (in-window? t)) "Drags region to a new location, which is returned ~ region cannot go outside limit (if provided). ~ If in-window? is non-nil, ~ then region and limit and result are in window coords ~ otherwise screen coords. ~ Axis contols the direction of dragging, values may be~ :x :y :both :none." (let (wb-limit wb-location) (setq limit (or limit (if in-window? (region-of window)))) (if limit (setq wb-limit (wb-region limit))) (setq wb-location (if in-window? (wb:drag-region-on-canvas window :region (wb-region region) :limit-region wb-limit :axis axis) (wb:drag-region-on-screen window :region (wb-region region) :axis axis))) (view-region wb-location))) (defun create-region-with-mouse (&optional window width height) (let (l b w h) (multiple-value-setq (l b w h) (wb:select-rectangle :canvas window :width width :height height)) (make-region l (+ l w) b (+ b h))))
17,377
Common Lisp
.l
370
35.897297
104
0.551108
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
1a3b6fbb689d259a49dfb5186a23277c447db167d88f9ef3f2a334bdc6def597
33,229
[ -1 ]
33,230
view-def.lsp
rwoldford_Quail/source/views/views-general/view-def.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; view-def.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '( view-p get-draw-portion get-map-portion transform-mapping-draw-portions add-viewport select-viewport make-default-viewport))) (defgeneric make-default-viewport (view) (:documentation "Returns a new viewport for view.")) (defgeneric get-draw-portion (self viewport) (:documentation "Returns the sub-region of viewport where self is drawn.")) (defgeneric get-map-portion (self region) (:documentation "Returns the sub-region of viewport where ~ bounding region of self is mapped.")) (defgeneric transform-mapping-draw-portions (self region transform) (:documentation "Transform maps region onto a new region. ~ Return a transform mapping region onto draw portion of new region.")) (defmethod make-draw-viewport ((self view) &optional title) (make-viewport title)) (defmethod get-draw-portion ((self view) viewport) viewport) (defmethod get-map-portion ((self view) viewport) (get-draw-portion self viewport)) (defmethod transform-mapping-draw-portions ((self view) region transform) (declare (ignore region)) transform) (defun view-p(view) "Tests for a view." (typep view 'view)) (defmethod subviews-of ((self view)) nil) (defmethod (setf subviews-of) (new (self view )) (declare (ignore new)) ) (defmethod visible-subs-p ((self view)) nil) (defmethod sub-view-locns-of ((self view)) nil) (defmethod (setf sub-view-locns-of) (new (self view)) (declare (ignore new))) (defmethod compute-map-to-viewport((self view) vp) (make-transform-for-regions (bounding-region-of self) (get-map-portion self vp))) (defmethod add-viewport ((self view) vp pvp &key (compute-transform? t)) ;; adds a VIEWPORT and PARENT-VIEWPORT, and the corresponding AFFINE-TRANSFORM ;; if PVP is already present, then install VP to correspond with PVP ;; if COMPUTE-TRANSFORM? is null, it is not installed. (let ((at (if compute-transform? (compute-map-to-viewport self vp)))) (with-accessors ((parent-viewports parent-viewports-of) (maps-to-viewports maps-to-viewports-of) (viewports viewports-of)) self (loop for vpi in parent-viewports for maps on maps-to-viewports for vps on viewports until (or (eql vpi pvp) (eql (car vps) vp)) finally (cond ((or (eql vpi pvp) (eql (car vps) vp)) (rplaca maps at) (rplaca vps vp)) (t (push pvp parent-viewports) (push at maps-to-viewports) (push vp viewports))))))) #| (defmethod delete-viewport ((self view) viewport) ;; remove the viewport VIEWPORT and corresponding MAP and PARENT-VIEWPORT (with-accessors ((viewports viewports-of) (maps maps-to-viewports-of) (parent-viewports parent-viewports-of)) self (loop for vp in viewports for m in maps for pvp in parent-viewports unless (eql vp viewport) collect vp into new-viewports and collect m into new-viewport-maps and collect pvp into new-parent-viewports finally (setf viewports new-viewports) (setf maps new-viewport-maps) (setf parent-viewports new-parent-viewports)))) |# (defmethod delete-viewport ((self view) viewport) ;; remove the viewport VIEWPORT and corresponding MAP and PARENT-VIEWPORT (with-accessors ((viewports viewports-of) (maps maps-to-viewports-of) (parent-viewports parent-viewports-of)) self (loop for vp in viewports for m in maps for pvp in parent-viewports until (eql vp viewport) finally (when (eq vp viewport) (setf viewports (delete vp viewports)) (setf maps (delete m maps)) (setf parent-viewports (delete pvp parent-viewports)))))) (defmethod delete-nested-viewports ((self view) vp) ;; deletes vp from self and ;; deletes the viewports corresponding to vp ;; from all subviews of self, recursively (loop for v in (subviews-of self) for sv-vp = (select-viewport v vp) do (delete-nested-viewports v sv-vp) ) (delete-viewport self vp)) (defmethod select-map-to-viewport ((self view) vp ) ;; select the MAP-TO-VIEWPORT corresponding to VP (let* ((pos (position vp (viewports-of self))) map) (when pos (setq map (elt (maps-to-viewports-of self) pos )) (unless map (setq map (compute-map-to-viewport self vp)) (setf (elt (maps-to-viewports-of self) pos ) map)) map))) (defmethod select-viewport ((self view) pvp) ;;; select the VIEWPORT corresponding to parent-viewport pvp (let ((pos (position pvp (parent-viewports-of self)))) (if pos (elt (viewports-of self) pos )))) (defmethod select-parent-viewport ((self view) vp) ;;; select the parent viewport corresponding to viewport vp (let ((pos (position vp (viewports-of self) ))) (if pos (elt (parent-viewports-of self) pos )))) (defmethod is-the-parent ((parent view) (sub view)) (member sub (subviews-of parent))) (defmethod list-viewports ((self view) &optional vp) (typecase vp (viewport (list vp)) (list vp) (t (viewports-of self)))) (defmethod select-sub-view-locn ((self view) (subview view)) ;;; select the sub-view-locn corresponding to subview (let ((pos (position subview (subviews-of self)))) (if pos (elt (sub-view-locns-of self) pos )))) (defmethod subview-location-string ((self view) (subview view)) (let ((r (select-sub-view-locn self subview))) (if r (format nil "~A,~A, ~A, ~A" (left-of r) (right-of r) (bottom-of r) (top-of r))))) ;;;======================================================================= #| (defmethod initialize-instance :after ((self view) &rest keyword-pairs &key draw? &allow-other-keys ) (apply #'construct-sub-views self keyword-pairs ) (apply #'initial-layout self keyword-pairs) (make-menus self) (if draw? (draw-view self)) ) |# (defun disable-keyword(keyword-pairs key) (let ((key-list (member key keyword-pairs))) (if key-list (setf (car key-list) (gensym (string key)))) keyword-pairs)) (defmethod initialize-instance :before ((self view) &key coord-string-x coord-string-y ) (if coord-string-x (defmethod coord-string-x ((view (eql self))) (if (functionp coord-string-x) (funcall coord-string-x view) coord-string-x))) (if coord-string-y (defmethod coord-string-y ((view (eql self))) (if (functionp coord-string-y) (funcall coord-string-y view) coord-string-y)))) (defmethod initialize-instance :after ((self view) &rest keyword-pairs) (disable-keyword keyword-pairs :initform-fn) (apply #'construct-sub-views self keyword-pairs ) (apply #'initial-layout self keyword-pairs) ) (defmethod auto-draw-p ((self view)) *auto-draw-view?*) (defmethod initialize-instance :around ((self view) &rest initargs &key (draw? :no-draw-val?) initform-fn link? (combine? t) &allow-other-keys) (disable-keyword initargs :link?) (when (and combine? (subview-keys-of self)) (setq initargs (apply #'combine-subview-args self initargs))) (if (functionp initform-fn) (apply #'call-next-method self (append (apply initform-fn initargs) initargs)) (apply #'call-next-method self initargs)) (if link? (if (typep link? 'link-table) (link-view self :draw? t :link-table link?) (link-view self :draw? t))) (if (or (eq draw? t) (and (eq draw? :no-draw-val? ) (auto-draw-p self))) (draw-view self)) ) (defmethod initial-layout ((self view) &rest keyword-pairs &key bounding-region &allow-other-keys) (if bounding-region ;;(apply #'set-bounding-region self :region bounding-region :pretty? nil keyword-pairs) (apply #'set-bounding-region self :region bounding-region (append keyword-pairs (list :pretty? nil))) (apply #'set-bounding-region self keyword-pairs )) (apply #'init-position-subviews self keyword-pairs)) (defmethod construct-sub-views ((self view) &key) ;; should be specialized for compound views ) (defmethod set-bounding-region ((self view) &key region (pretty? t) ignore-x? ignore-y?) ;; if pretty? is non-nil the view may expand the bounding region to ;; cover a "pretty" region ;; if ignore-x? is non-nil the x bounds view remain unchanged ;; similarly ignore-y? (declare (ignore pretty?)) (let ((new-region (or (and region (if (or ignore-x? ignore-y?) (make-region region) region)) (compute-bounding-region self)))) (if (or ignore-x? ignore-y?) (let ((old-bounds (or (bounding-region-of self) (make-region)))) (if ignore-x? (setf (x-extent-of new-region) old-bounds)) (if ignore-y? (setf (y-extent-of new-region) old-bounds)))) (setf (bounding-region-of self) new-region))) (defmethod compute-bounding-region ((self view) ) (make-region)) (defmethod compute-bounding-region :around ((self view) ) (let ((region (call-next-method))) (setq region (loop until (valid-region-check region nil) do (setq region (apply #'make-region (wb:prompt-user :result-type 'list :read-type :read :prompt-string (format nil "Enter bounds for ~S, (left right bottom top)" self)))) finally (return region))))) (defmethod init-position-subviews ((self view) &key) ;; should be specialized for compound views ) (defmethod place-subview ((self view) (subview view) locn ) ;; adds the location in self for SUBVIEW ;; if SUBVIEW is not already in subviews-of self add it (with-accessors ((subviews subviews-of) (subview-locns sub-view-locns-of)) self (unless subview-locns (setf subview-locns (make-list (length subviews)))) (loop for s in subviews for l on subview-locns until (eql s subview) finally (if (eql s subview) (rplaca l locn) ;; else (progn (push subview subviews) (push locn subview-locns)))))) (defmethod delete-subview ((self view) subview) (declare (ignorable self subview)) ;(declare (ignore self subview)); 29JUL2023 ) ;;;================================================================================ (defmethod map-to-viewport ((self view) &optional viewport) (loop for vp in (if viewport (list viewport) (viewports-of self)) do (add-viewport self vp vp) (map-subviews-to-viewport self vp))) (defmethod map-subviews-to-viewport ((self view) &optional viewport subviews) ;; if VIEWPORT is not provided, this is performed for all VIEWPORTS ;; if subviews is not provided, this is performed for all subviews (loop for vp in (if viewport (list viewport) (viewports-of self)) do (compute-sub-viewports self vp subviews) (loop for sv in (or subviews (subviews-of self)) for sv-vp = (select-viewport sv vp) do (map-subviews-to-viewport sv sv-vp)))) (defmethod compute-sub-viewports ((self view) &optional viewport subviews) ;; obtains viewports (contained in viewport) for subviews ;; if VIEWPORT is not provided, this is performed for all VIEWPORTS (let ((viewports (if viewport (list viewport) (viewports-of self))) (maps (if viewport (list (select-map-to-viewport self viewport)) (maps-to-viewports-of self))) (subview-locns (if subviews (loop for s in subviews collect (select-sub-view-locn self s)) (sub-view-locns-of self)))) (setq subviews (or subviews (subviews-of self))) (loop for sv in subviews for svl in subview-locns do (loop for vp in viewports for map in maps for sv-vp = (or (select-viewport sv vp) (make-viewport (window-of vp))) do (setf (bounds-of sv-vp) (apply-transform map svl)) (add-viewport sv sv-vp vp))))) (defmethod allowed-subview-movement ((self view) subview) ;; may returns :x :y :both or :none ;; determines how subview may be moved within view (declare (ignore subview)) :both) (defmethod list-viewed-elements ((self view)) (let ((vo (viewed-object-of self))) (if vo (list vo)))) (defmethod legal-subview-p ((self view) subview) (declare (ignore subview)) t) (defmethod delete-all-subviews ((self view))) (defmethod use-y-axis-p ((self view)) nil) (defmethod use-x-axis-p ((self view)) nil) (defmethod show-y-axis-p ((self view)) (use-y-axis-p self)) (defmethod show-x-axis-p ((self view)) (use-x-axis-p self)) (defmethod subview-locns-of ((self view)) (sub-view-locns-of self)) (defmethod (setf subview-locns-of) (new (self view)) (setf (sub-view-locns-of self) new)) (defmethod sub-views-of ((self view)) (subviews-of self)) (defmethod (setf sub-views-of) (new (self view )) (setf (subviews-of self) new)) (defmethod view-title-string ((self view)) nil ) (defmethod compute-descendant-locn((self view) (d view)) (or (select-sub-view-locn self d) (loop for sv in (sub-views-of self) for dl = (if (typep sv 'compound-view) (compute-descendant-locn sv d)) until dl finally (if dl (return (let ((tr (make-transform-for-regions (bounding-region-of sv) (select-sub-view-locn self sv)))) (apply-transform tr dl)))))))
16,143
Common Lisp
.l
357
34.529412
109
0.576447
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
777adbb14ea89eebecc02815d5675912dc20c821afb7ec8c4bd42725a0ffcf46
33,230
[ -1 ]
33,231
draw-styles.lsp
rwoldford_Quail/source/views/views-general/draw-styles.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; draw-styles.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(drawing-style-p make-drawing-style list-style-keys has-draw-style-p draw-style set-draw-style add-style new-style-value prompt-for-style ))) (defgeneric has-draw-style-p (draw-style style-key) (:documentation "Returns non-nil if draw-style has a value for style-key ")) (defgeneric draw-style (draw-style style-key &key &allow-other-keys) (:documentation "Returns value of draw-style for style-key. ~ It is an error if draw-style does not have such a value")) (defgeneric set-draw-style (draw-style style-key value &key &allow-other-keys) (:documentation "Sets value of draw-style for style-key. ~ It is an error if draw-style does not have such a value")) (defgeneric add-style (draw-style style-name value) (:documentation "Adds a style style-name with value to draw-style")) (defgeneric copy-style-values (ds1 ds2) (:documentation "Copy style values from ds1 to ds2")) (defgeneric new-style-value (style-name new pair) (:documentation "Returns new value for style name. ")) (defgeneric prompt-for-style (style) (:documentation "Returns new value for style ")) ;;;---------------------------------------------------------------------------------- (defun make-drawing-style (&rest keyword-pairs &key &allow-other-keys) (loop for kw in keyword-pairs by #'cddr for kw-val in (cdr keyword-pairs) by #'cddr unless (assoc kw result) collect (cons kw kw-val) into result finally (return result))) (defun drawing-style-p(arg) (and (listp arg) (consp (car arg)))) (defun copy-drawing-style (ds) (copy-alist ds)) (defmethod copy-style-values (ds1 ds2) (loop for pair in ds1 do (set-draw-style ds2 (car pair) (cdr pair)))) (defmethod draw-style (ds style-name &key (default nil supplied-p)) (let ((pair (assoc style-name ds))) (if pair (cdr pair) (if supplied-p default (quail-error "~S does not have drawing style ~S" ds style-name))))) (defmethod has-draw-style-p (ds style-name) (assoc style-name ds)) (defmethod new-style-value (style-name new pair) (declare (ignorable pair style-name)) ;(declare (ignore pair style-name)) ; 29JUL2023 new) (defmethod new-style-value ((style-name (eql :size)) new pair) (unless (numberp new) (setq new (case new (:larger (+ (cdr pair) (if (>= (cdr pair) 3) 2 1))) (:smaller (- (cdr pair) (if (<= (cdr pair) 3) 1 2))) (t (cdr pair))))) (max 1 new)) (defmethod new-style-value ((style-name (eql :font)) new pair) (if (wb:canvas-font-p new) new (new-font-size (cdr pair) new))) (defmethod new-style-value ((style-name (eql :width)) new pair) (if (numberp new) new (case new (:fatter (1+ (cdr pair))) (:thinner (1- (cdr pair))) (:prompt (wb:prompt-user :result-type 'number :read-type :eval :prompt-string (format nil "Change size from ~A" (cdr pair)))) (t (cdr pair))))) (defmethod new-style-value (style-name (new (eql :toggle)) pair) (declare (ignorable style-name)) ;(declare (ignore style-name)) ;; 29JUL2023 (not (cdr pair))) (defmethod new-style-value ((style-name (eql :highlight?)) new pair) (declare (ignorable style-name)) ;(declare (ignore style-name)) ; 29JUL2023 (case new (:toggle (not (cdr pair))) (t new))) (defmethod new-style-value ((style-name (eql :orientation)) new pair) (case new (:toggle (if (eq :horizontal (cdr pair)) :vertical :horizontal)) (t new))) (defmethod new-style-value ((style-name (eql :color)) new pair) (declare (ignorable pair)) ;(declare (ignore pair)) ; 29JUL2023 (if (eq new :prompt) (wb:prompt-user-for-color) new)) (defmethod prompt-for-style (style) (declare (ignorable style)) T) (defmethod prompt-for-style ((style-name (eql :color))) (wb:prompt-user-for-color)) (defmethod prompt-for-style ((style-name (eql :font))) (wb:prompt-user :prompt-string "Enter the new font size (1 to 127): " :result-type 'integer :read-type :eval)) (defmethod set-draw-style (ds style-name val &key) (let ((pair (assoc style-name ds))) (if pair (setf (cdr pair) (new-style-value style-name val pair))))) (defmethod add-style (ds style-name value) (if (has-draw-style-p ds style-name) (set-draw-style ds style-name value) (nconc ds (cons (cons style-name value) nil)))) ;;------------------------------------------------------------------------------------------ (defun find-pairs (key-pairs keys) (if keys (loop for k in key-pairs by #'cddr for val in (cdr key-pairs) by #'cddr when (member k keys) collect k and collect val))) (defun list-style-keys(ds) (loop for d in ds collect (car d)))
5,956
Common Lisp
.l
133
37.368421
117
0.571983
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
55b8507c541320fadca38437d04432b5e6835953e8f9b5b421fe3380c658e956
33,231
[ -1 ]
33,232
linkbounds.lsp
rwoldford_Quail/source/views/views-general/linkbounds.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; linkbounds.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(linkable-bounds-mixin link-bounds-x-of link-bounds-y-of link-bounds-of compute-relative-transforms maximize-x-extents maximize-y-extents set-view-extents link-view-bounds unlink-view-bounds))) ;;;---------------------------------------------------------------------------------- ;; For constraints between the bounding-regions of views. ;; Views can be constrained to have the same x,y (or both) extent, ;; More generally, an extent may be constrained to another by a ;; (linear) transformation). (defclass linkable-bounds-mixin () ((link-bounds :initform (list nil nil )))) (defmethod initialize-instance :after ((self linkable-bounds-mixin) &key (linkable-bounds-x? t) (linkable-bounds-y? t)) (unless (eq t linkable-bounds-x?) (setf (first (slot-value self 'link-bounds)) :no-link)) (unless (eq t linkable-bounds-y?) (setf (second (slot-value self 'link-bounds)) :no-link))) (defmethod linkable-bounds-x-p ((self linkable-bounds-mixin )) (if (listp (first (slot-value self 'link-bounds))) self)) (defmethod linkable-bounds-y-p ((self linkable-bounds-mixin )) (if (listp (second (slot-value self 'link-bounds))) self)) (defmethod link-bounds-x-of (( self linkable-bounds-mixin )) (cons self (if (linkable-bounds-x-p self) (remove self (first (slot-value self 'link-bounds)))))) (defmethod link-bounds-y-of (( self linkable-bounds-mixin )) (cons self (if (linkable-bounds-y-p self) (remove self (second (slot-value self 'link-bounds)))))) (defmethod link-bounds-of (( self linkable-bounds-mixin )) (cons self (remove self (union (link-bounds-x-of self) (link-bounds-y-of self))))) (defmethod remove-y-link (( self linkable-bounds-mixin ) v) (if (linkable-bounds-y-p self) (setf (second (slot-value self 'link-bounds)) (remove v (second (slot-value self 'link-bounds)))))) (defmethod remove-x-link (( self linkable-bounds-mixin ) v) (if (linkable-bounds-x-p self) (setf (first (slot-value self 'link-bounds)) (remove v (first (slot-value self 'link-bounds)))))) (defmethod link-bounds-x-of((view-list list)) (remove-duplicates (loop for v in view-list when v nconc (link-bounds-x-of v)))) (defmethod link-bounds-y-of((view-list list)) (remove-duplicates (loop for v in view-list when v nconc (link-bounds-y-of v)))) (defmethod (setf link-bounds-x-of) (new-list ( self linkable-bounds-mixin )) (if (linkable-bounds-x-p self) (setf (first (slot-value self 'link-bounds)) new-list))) (defmethod (setf link-bounds-y-of) (new-list ( self linkable-bounds-mixin )) (if (linkable-bounds-y-p self) (setf (second (slot-value self 'link-bounds)) new-list))) (defun link-view-bounds(views axis) (if (eq axis :x) (loop for v in views do (setf (link-bounds-x-of v) views)) (loop for v in views do (setf (link-bounds-y-of v) views)))) (defun unlink-view-bounds(views v axis) "Unlink v from views." (let (new-links ) (if (eq axis :x) (setf new-links (remove v (link-bounds-x-of (car views))) (link-bounds-x-of v) nil) (setf new-links (remove v (link-bounds-y-of (car views))) (link-bounds-y-of v) nil)) (link-view-bounds new-links axis))) #| (defun region+region (r1 r2) (cond ((and (region-p r1) (region-p r2)) (make-region (+ (left-of r2) (left-of r1)) (+ (right-of r2) (right-of r1)) (+ (bottom-of r2) (bottom-of r1)) (+ (top-of r2) (top-of r1)))) ((region-p r1) r1) ((region-p r2) r2) (t nil))) (defun region-region (r1 r2) (cond ((and (region-p r1) (region-p r2)) (make-region (- (left-of r1) (left-of r2)) (- (right-of r1) (right-of r2)) (- (bottom-of r1) (bottom-of r2)) (- (top-of r1) (top-of r2)))) ((region-p r1) r1) ((region-p r2) r2) (t nil))) |# (defun maximize-x-extents (views) "Computes the region maximizing the x-extent of views." (loop for v in views for br = (bounding-region-of v) maximize (right-of br) into right minimize (left-of br) into left finally (loop with b for v in views when (typep v 'one-per-case-mixin) do (setq b (adjusted-bounding-region v)) (if (or (not (typep v 'orientation-mixin)) (eq (orientation-of v) :horizontal)) (setq left (min left (left-of b)) right (max right (right-of b))))) (return (make-region left right 0 1)))) (defun maximize-y-extents (views) "Computes the region maximizing the y-extent of views." (loop for v in views for br = (bounding-region-of v) maximize (top-of br) into top minimize (bottom-of br) into bottom finally (loop with b for v in views when (typep v 'one-per-case-mixin) do (setq b (adjusted-bounding-region v)) (if (or (not (typep v 'orientation-mixin)) (eq (orientation-of v) :vertical)) (setq bottom (min bottom (bottom-of b)) top (max top (top-of b))))) (return (make-region 0 1 bottom top)))) (defun set-view-extents (views axis &key region (recompute? t)) "Gives all views the same extent along axis-- from region.~ If region is not present, maximize the extents of views." (let ((new-region nil) (new-extent (if (eq axis :x) #'(lambda (v new-br) (setf (x-extent-of (bounding-region-of v)) new-br) (if recompute? (if (typep v 'line) (compute-line-endpoints v) (if (and (typep v 'axis) (eql (orientation-of v) :horizontal)) (let ((old (internal-tics-p v))) (setf (internal-tics-p v) t) (get-tic-interval v) (setf (internal-tics-p v) old)))))) #'(lambda (v new-br) (setf (y-extent-of (bounding-region-of v)) new-br) (if recompute? (if (typep v 'line) (compute-line-endpoints v) (if (and (typep v 'axis) (eql (orientation-of v) :vertical)) (let ((old (internal-tics-p v))) (setf (internal-tics-p v) t) (get-tic-interval v) (setf (internal-tics-p v) old))))))))) (setq new-region (or region (if (eq axis :x) (maximize-x-extents views) (maximize-y-extents views)))) (loop for v in views for i upfrom 0 for newb = new-region do (funcall new-extent v newb)))) (defmethod change-bounding-region ((self linkable-bounds-mixin) region &key ignore-x? ignore-y? (pretty? t) (draw? t) ) "Sets bounding-region of self to region ~ and redraws everywhere. If ignore-x? is non-nil the x bounds view remain unchanged.~ similarly ignore-y?. ~ Views with linked bounds are also modified." (unless (and ignore-x? ignore-y? ) (let* ((x-views (link-bounds-x-of self)) (y-views (link-bounds-y-of self)) (redraw-views nil) ) (setq redraw-views (union (unless ignore-x? x-views) (unless ignore-y? y-views))) (if draw? (loop for v in redraw-views do (erase-view v ))) (unless ignore-x? (change-bounding-region-views x-views region :ignore-y? t :pretty? pretty? :draw? nil)) (unless ignore-y? (change-bounding-region-views y-views region :ignore-x? t :pretty? pretty? :draw? nil)) (if draw? (loop for v in redraw-views do (remap-to-viewports v :erase? nil)))))) (defun set-bounding-regions (views region &key ignore-x? ignore-y? (pretty? t) ) "Sets bounding-region of views to region.~ If ignore-x? is non-nil the x bounds view remain unchanged ~ similarly ignore-y?.~ A non-nil pretty? allows regions to be prettied." (loop for v in views do (set-bounding-region v :region region :ignore-x? ignore-x? :ignore-y? ignore-y? :pretty? pretty?))) (defun change-bounding-region-views (views region &key ignore-x? ignore-y? (pretty? t) (draw? t)) "Sets bounding-region of views to region and redraws views.~ If ignore-x? is non-nil the x bounds view remain unchanged,~ similarly ignore-y?.~ A non-nil pretty? allows regions to be prettied." (unless (and ignore-x? ignore-y? ) (if draw? (loop for v in views do (erase-view v ))) (set-bounding-regions views region :ignore-x? ignore-x? :ignore-y? ignore-y? :pretty? pretty?) (when pretty? (unless ignore-x? (set-view-extents views :x)) (unless ignore-y? (set-view-extents views :y ))) (if draw? (loop for v in views do (remap-to-viewports v :erase? nil)))))
11,281
Common Lisp
.l
233
34.575107
106
0.512572
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
53a3b1a0e27a954303827899ed6be8f35953e2d135a122dbd96cba1a8ebb4ecf
33,232
[ -1 ]
33,233
abstract-views.lsp
rwoldford_Quail/source/views/views-general/abstract-views.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; abstract-views.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(simple-view compound-view list-viewed-elements))) ;;;---------------------------------------------------------------------------------- (defclass simple-view (viewed-elements-mixin view) ((right-menu :allocation :class :initform nil) )) (defmethod description-string ((self simple-view)) (let* ((vo (viewed-object-of self)) (name (dataset-name vo))) (if (and name (not (equal name "NIL"))) (format nil "~A viewing ~A" self name) (format nil "~A" self)))) (defmethod get-menu-items :around ((self simple-view) (slot-name (eql 'right-menu))) (let ((result (call-next-method)) (layers (append (loop for (string sym) in (view-menu-list '(and simple-view (not d-view ))) collect `(,string (layer-view ,sym :viewport))) `(("Selected" (layer-selected-view :viewport )))))) (add-menu-items self result `(("Paste" nil "" :sub-items ,layers))))) (defclass compound-view (view) ((subview-position-region :initform nil :accessor subview-position-region-of :documentation "Region where subviews are positioned.") (subviews :initform nil ;;:initarg :subviews :accessor subviews-of :documentation "Subviews in a list") (sub-view-locns :initform nil ;; :initarg :subview-locns :accessor sub-view-locns-of :documentation "Subviews in a list") (visible-subs? :initform nil :accessor visible-subs-p :documentation "keeps track of which subs are currently inside self (usually all"))) (defmethod default-drawing-style :around ((self simple-view) &rest keyword-pairs &key (color nil)) (apply #'call-next-method self :color color keyword-pairs )) (defmethod place-subview ((self simple-view) (subview view) locn ) (declare (ignore locn)) (quail-error "~A is a simple-view and cannot have subviews, ~A is ignored")) (defmethod (setf subviews-of) (new-value (self simple-view) ) (unless (null new-value) (quail-cerror "~A is a simple-view and cannot have subviews, ~A is ignored" self new-value))) (defmethod delete-subview ((self simple-view) subview) (quail-cerror "~A is a simple-view and has no subviews, ~A is ignored" self subview)) (defmethod legal-subview-p ((self simple-view) subview) (declare (ignore subview )) nil) ;;;================================================================================ (defmethod subview-position-region ((self compound-view )) (or (subview-position-region-of self) (bounding-region-of self))) (defmethod recompute-visible-subs ((self compound-view )) (setf (visible-subs-p self) (visible-subviews-p self))) (defmethod set-bounding-region :around ((self compound-view ) &rest ignore ) (declare (ignore ignore)) (call-next-method) (recompute-visible-subs self )) (defmethod init-position-subviews ((self compound-view ) &key) (loop with br = (bounding-region-of self) for sv in (subviews-of self) do (place-subview self sv br))) (defmethod init-position-subviews :around ((self compound-view ) &key) (if (subview-position-region-of self) (setf (subview-position-region-of self) (make-region (bounding-region-of self)))) (call-next-method) (recompute-visible-subs self )) #| (defmethod some-subviews((self compound-view) &key highlit?) (cond ((null highlit?) (loop for sv in (subviews-of self) for inside? in (visible-subs-p self) when inside? collect sv)) ((eq t highlit?) (loop for sv in (subviews-of self) for inside? in (visible-subs-p self) when (and inside? (any-highlight? sv)) collect sv)) (t (or (some-subviews self :highlit? t) (some-subviews self :highlit? nil))))) |# (defun has-highlit-subviews?(view) (or (any-highlight? view) (loop for v in (subviews-of view) thereis (has-highlit-subviews? v)))) (defmethod some-subviews((self compound-view) &key highlit?) (cond ((null highlit?) (loop for sv in (subviews-of self) for inside? in (visible-subs-p self) when inside? collect sv)) ((eq t highlit?) (loop for sv in (subviews-of self) for inside? in (visible-subs-p self) when (and inside? (has-highlit-subviews? sv)) collect sv)) (t (or (some-subviews self :highlit? t) (some-subviews self :highlit? nil))))) (defmethod delete-subview ((self compound-view) subview) ;; remove subview and its location from self (with-accessors ((sub-views subviews-of) (sub-view-locns sub-view-locns-of)) self (loop for sv in sub-views for svl in sub-view-locns until (eql sv subview) finally (when (eql sv subview) (setf sub-views (delete subview sub-views)) (setf sub-view-locns (delete svl sub-view-locns)))))) (defmethod add-subview :after ((self compound-view ) subview new-region) (declare (ignore new-region)) (when (legal-subview-p self subview) (recompute-visible-subs self ))) (defmethod delete-subview :after ((self compound-view ) subview ) (let* ((views (list-subviews self :test #'(lambda(v) (typep v 'linkable-bounds-mixin)))) (px (find subview views :key #'link-bounds-x-of :test #'member)) (py (find subview views :key #'link-bounds-y-of :test #'member)) ) (if px (unlink-view-bounds (link-bounds-x-of px) subview :x)) (if py (unlink-view-bounds (link-bounds-y-of py) subview :y))) (recompute-visible-subs self )) (defmethod layer-subview :after ((self compound-view) view on &rest arg) (declare (ignore arg view on)) (recompute-visible-subs self )) (defmethod styles-to-subs ((self compound-view) ) nil) (defmethod set-drawing-style :around ((self compound-view) &rest key-args &key highlit? element styles) (let ((styles-to-subs (styles-to-subs self)) (style-pairs (or styles key-args)) my-styles other-styles) (loop for style in style-pairs by #'cddr for val in (cdr style-pairs) by #'cddr unless (or (eq style :highlit?) (eq style :element)) do ;; (if (and (eq style :color) ;; (eq val :prompt)) ;; (setf val (wb::prompt-user-for-color))) (if (eq val :prompt) (setf val (prompt-for-style style))) (if (has-draw-style-p self style) (if (member style styles-to-subs) (progn (set-draw-style self style val) (push (draw-style self style) other-styles) (push style other-styles)) (progn (push val my-styles) (push style my-styles))) (progn (push val other-styles) (push style other-styles)))) (if my-styles (apply #'call-next-method self :element element :styles my-styles key-args)) (if other-styles (with-update-style-cache (loop with sv-args+ = (append other-styles (list :element element :highlit? highlit?)) for v in (some-subviews self :highlit? highlit?) do (apply #'set-drawing-style v sv-args+ )))))) (defmethod set-highlight-style :around ((self compound-view) hi-val &rest key-args &key highlit? element) (if (member :highlight? (styles-to-subs self)) (progn (set-draw-style self :highlight? hi-val) (setq hi-val (draw-style self :highlight?)) (with-update-style-cache (loop with sv-args+ = (list :element element) for v in (some-subviews self :highlit? highlit?) do (apply #'set-highlight-style v hi-val sv-args+ )))) (apply #'call-next-method self hi-val :element element key-args))) ;;;================================================================================ (defmethod delete-all-subviews ((self compound-view)) (setf (subviews-of self) nil) (setf (sub-view-locns-of self) nil))
9,762
Common Lisp
.l
221
33.864253
116
0.547341
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4ab74605c0535f0b50eeed28da21047fa1aadd2ee6ba7102ab51cf7f38ceac1b
33,233
[ -1 ]
33,234
make-views.lsp
rwoldford_Quail/source/views/views-general/make-views.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; make-views.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-view-constructor make-view-constructor-with-doc make-view-constructor-fn make-view-constructor-doc-string choose-view-from-menu *view-constructors* ))) (defun make-view-constructor-fn (default-class &rest default-args) "Returns a function which constructs a view ~ of default class default-class. ~ Default-args are passed on to the view construction." #'(lambda(&rest args) (let* ((type-arg (getf args :type :none)) (view-class (unless (eql :none type-arg) (and (symbolp type-arg) (or (get type-arg 'view-class) (and (subtypep type-arg 'view) type-arg))))) (new-args (append (if (eql :none type-arg) args (disable-keyword args :type)) default-args)) (new-view (if (functionp type-arg) (apply type-arg new-args) ))) (cond ((and new-view (typep new-view default-class)) new-view) ((and view-class (subtypep view-class default-class) (fboundp type-arg)) (apply (symbol-function type-arg) new-args)) ((and view-class (subtypep view-class default-class)) (apply #'make-instance view-class new-args)) ((and (fboundp type-arg) (setq new-view (apply (symbol-function type-arg) new-args)) (typep new-view default-class)) new-view) (t (apply #'make-instance default-class new-args)))))) (defun make-view-constructor-doc-string(default-class) ;(declare (ignore default-args)) 10MAR2022 gwb probably a cut+paste (format nil "This function constructs and returns a ~A." default-class )) (defvar *view-constructors* nil "A list of symbols naming functions which construct views") (defun make-view-constructor(function-name default-class doc &rest default-args) "Creates a function named function-name which constructs a view~ of default class default-class. ~ Default-args are passed on to the view construction. ~ Function is exported" (eval-when (:compile-toplevel :load-toplevel :execute) (export `(,function-name))) (setf (documentation function-name 'function) doc) (setf (symbol-function function-name) (apply #'make-view-constructor-fn default-class default-args)) (setf (get function-name 'view-class) default-class) (pushnew function-name *view-constructors*) (symbol-function function-name)) (defun make-view-constructor-with-doc(function-name default-class &rest default-args) "Creates a function named function-name which constructs a view~ of default class default-class. ~ Default-args are passed on to the view construction. ~ A documentation string for function-name is built.~ Function is exported" (let ((doc (make-view-constructor-doc-string default-class))) (apply #'make-view-constructor function-name default-class doc default-args))) (defun choose-view-from-menu(&key (superclass 'view) menu-list (prompt-string "Select a view class")) "Gives the user a list of view classes which inherit ~ from superclass to choose from.~ Superclass can also be a list of class names whose first ~ member is and or or. " (setq menu-list (or menu-list (select-view-menu-list superclass))) (if (= (length menu-list) 1) (cadar menu-list) (choose-views-from-menu :superclass superclass :prompt-string prompt-string :menu-list menu-list :nmax 1))) (defun choose-views-from-menu(&key (superclass 'view) menu-list (prompt-string "Select a view class") nmax) "Gives the user a list of view classes which inherit ~ from superclass to choose upto nmax views from. ~ Superclass can also be a list of class names whose first ~ member is and or or. " (setq menu-list (or menu-list (select-view-menu-list superclass))) (if (eq nmax 1) (loop for res = (cadar (wb:prompt-for-items menu-list :prompt-text prompt-string :item-function #'first)) until res finally (return res)) (loop append (wb:prompt-for-items menu-list :prompt-text prompt-string :item-function #'first :selection-type :disjoint) into result-list until (or (null nmax) (and nmax (>= (length result-list) nmax))) finally (return (if (and nmax (> (length result-list) nmax)) (mapcar #'second (subseq result-list 0 nmax)) (mapcar #'second result-list)))))) (make-view-constructor-with-doc 'view 'view ) (make-view-constructor-with-doc 'point-symbol 'point-symbol ) (make-view-constructor-with-doc 'box 'point-symbol :symbol :box) (make-view-constructor-with-doc 'circle 'point-symbol :symbol :circle) (make-view-constructor-with-doc 'cross 'point-symbol :symbol :cross) (make-view-constructor-with-doc 'diamond 'point-symbol :symbol :diamond ) (make-view-constructor-with-doc 'star 'point-symbol :symbol :star) (make-view-constructor-with-doc 'poly-star 'point-symbol :symbol :poly-star) (make-view-constructor-with-doc 'triangle 'point-symbol :symbol :triangle) (make-view-constructor-with-doc 'bar 'bar ) (make-view-constructor-with-doc 'box 'box ) (make-view-constructor-with-doc 'pie 'pie ) (make-view-constructor-with-doc 'function-view 'function-view ) (make-view-constructor-with-doc 'label 'label ) (make-view-constructor-with-doc 'linkable-label 'label :linkable? t) (make-view-constructor-with-doc 'group-label 'group-label ) (make-view-constructor-with-doc 'line-segment 'line-segment ) (make-view-constructor-with-doc 'line-segments 'line-segment ) (make-view-constructor-with-doc 'line 'line ) (make-view-constructor-with-doc 'horizontal-line 'line :orientation :horizontal ) (make-view-constructor-with-doc 'vertical-line 'line :orientation :vertical ) (make-view-constructor-with-doc 'text-view 'text-view ) (make-view-constructor-with-doc 'control-button 'control-button ) (make-view-constructor-with-doc 'rounded-button 'rounded-button ) (make-view-constructor-with-doc 'signpost-button 'signpost-button ) (make-view-constructor-with-doc 'elliptical-button 'elliptical-button ) (make-view-constructor-with-doc 'bar-slider 'bar-slider ) (make-view-constructor-with-doc 'needle-slider 'needle-slider ) (make-view-constructor-with-doc 'double-bar-slider 'double-bar-slider ) (make-view-constructor-with-doc 'double-needle-slider 'double-needle-slider ) (make-view-constructor-with-doc 'axis 'axis ) (make-view-constructor-with-doc 'fringe-view '1d-point-cloud :case-view '(:type oriented-line :orientation :vertical) ) (make-view-constructor-with-doc 'boxplot-view 'boxplot-view ) (make-view-constructor-with-doc 'interval-view 'interval-view ) (make-view-constructor-with-doc 'fitted-line 'fitted-line ) (make-view-constructor-with-doc 'histogram-view 'histogram-view ) (make-view-constructor-with-doc 'lines 'lines ) (make-view-constructor-with-doc 'simple-lines 'simple-lines ) (make-view-constructor-with-doc 'point-cloud '2d-point-cloud ) (make-view-constructor-with-doc '2d-point-cloud '2d-point-cloud ) (make-view-constructor-with-doc '2d-image '2d-image ) (make-view-constructor-with-doc 'line-segments-per-case 'line-segments-per-case ) (make-view-constructor-with-doc '1d-point-cloud '1d-point-cloud ) (make-view-constructor-with-doc 'smoothed-2d-point-cloud 'smoothed-2d-point-cloud ) (make-view-constructor-with-doc 'simple-smooth 'simple-smooth ) (make-view-constructor-with-doc 'smooth 'smooth ) (make-view-constructor-with-doc 'rotating-point-cloud 'rotating-cloud ) (make-view-constructor-with-doc 'simple-lines 'simple-lines ) (make-view-constructor-with-doc 'arrow 'arrow ) (make-view-constructor-with-doc 'view-layout 'view-layout ) (make-view-constructor-with-doc 'grid-layout 'grid-layout ) (make-view-constructor-with-doc 'table-layout 'table-layout ) (make-view-constructor-with-doc '1way-layout '1way-layout :format :row ) (make-view-constructor-with-doc 'row-layout 'grid-layout :format :row) (make-view-constructor-with-doc 'col-layout 'grid-layout :format :col) (make-view-constructor-with-doc 'batch-layout 'batch-layout ) (make-view-constructor-with-doc '1d-layout '1d-layout ) (make-view-constructor-with-doc 'xy-layout 'xy-layout ) (make-view-constructor-with-doc 'bar-chart 'bar-chart ) (make-view-constructor-with-doc 'pairs-layout 'pairs-layout ) (make-view-constructor-with-doc 'view-layers 'view-layers ) (make-view-constructor-with-doc 'scroll-bar 'scroll-bar ) (make-view-constructor-with-doc 'scrolling-display 'scrolling-display )
10,030
Common Lisp
.l
179
47.335196
100
0.645575
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5ee256dab621d0f58fd3d1862b37109b60e396c01b8a5573bfb49a174ccc7396
33,234
[ -1 ]
33,235
special-vars-bw.lsp
rwoldford_Quail/source/views/views-general/special-vars-bw.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; special-vars-bw.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (setq wb:*default-canvas-background-color* wb:*white-shade*) (setq wb:*default-canvas-pen-color* wb:*black-shade*)
857
Common Lisp
.l
23
33.652174
92
0.396766
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d19ebc933bc14bee9fa36e9df8709e4aaef3874d28b8cf399f5cbf485f05c3dc
33,235
[ -1 ]
33,236
display.lsp
rwoldford_Quail/source/views/views-general/display.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; display.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1993, 1995, 1996 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(display signposts display-viewed-object))) (defclass displayable-mixin () ((displayed-view :accessor displayed-view-of :initform NIL :documentation "Slot to cache the display view of a quail-object.") (displayed-args :accessor displayed-args-of :initform NIL :documentation "Slot to cache the arguments used to ~ create the cached display.")) (:documentation "A class used to cache the display view of any quail-object.")) (eval-when (:execute :load-toplevel) ;(eval load) 10MAR2022 gwb (qk::add-mixin-to-quail-object 'displayable-mixin)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; DISPLAY ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defgeneric display (thing &rest keyword-args &key draw? &allow-other-keys) (:documentation "Produces a display of thing. Keyword arguments are specialized by methods. ~ These will include at least view style arguments.")) (defun display-viewed-object (view &rest keyword-args) "A function that will call display on the viewed-object of the given ~ view. Keword-args are passed on to the display method for that viewed-object." (apply #'display (viewed-object-of view) keyword-args)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; SIGNPOSTS ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defgeneric signposts (quail-object &rest keyword-args &key &allow-other-keys) (:documentation "Returns a single view or list of views (typically control buttons) ~ that will act as signposts to new analysis steps from a display of this ~ quail-object.")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Caching the displayed view ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defmethod display :around ((thing displayable-mixin) &rest keyword-args &key (viewport NIL) (draw? T) (new? NIL) &allow-other-keys) "Caches the displayed view and re-uses it when it exists." (if (or new? (null (displayed-view-of thing)) (not (equal keyword-args (displayed-args-of thing)))) (let ((result (call-next-method))) (setf (displayed-view-of thing) result) (setf (displayed-args-of thing) keyword-args) result) (let ((result (displayed-view-of thing))) (if draw? (if viewport (apply #'draw-view result :viewport viewport keyword-args) (apply #'draw-view result :viewport (or viewport (make-viewport)) keyword-args) )) result) ) )
3,528
Common Lisp
.l
84
35.916667
108
0.487353
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
7026443709c79da1d4f8edc1761f6d22c5fd86d96dfbbf153f352a0badaaf269
33,236
[ -1 ]
33,237
special-vars.lsp
rwoldford_Quail/source/views/views-general/special-vars.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; special-vars.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*color-menu-list* *shade-menu-list* nil *default-point-color* *default-axis-color* *default-bar-color* *default-curve-color* *default-label-color* *default-highlight-color* *point-symbol-types* *default-point-size* *default-point-symbol* *default-label-font* *default-menu-font* *variable-transforms* *default-brush-width* *default-brush-height* *view-fonts* new-font-size color-to-string *default-draw-rate* *variable-summaries* ))) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(set-up-default-window-region))) (defvar *color-menu-list*) (setq *color-menu-list* `(("red" ,wb:*red-color*) ( "blue" ,wb:*blue-color*) ( "green" ,wb:*green-color*) ( "yellow" ,wb:*yellow-color*) ( "magenta" ,wb:*magenta-color*) ( "black" ,wb:*black-color*) ("light gray" ,wb:*light-gray-color*) ("gray" ,wb:*gray-color*) ("dark gray" ,wb:*dark-gray-color*) ( "white" ,wb:*white-color*) ("Other" :prompt) )) (defvar *shade-menu-list* `(("light gray" ,wb:*light-gray-color*) ("gray" ,wb:*gray-color*) ("dark gray" ,wb:*dark-gray-color*) ( "black" ,wb:*black-color*) ( "white" ,wb:*white-color*) ("Other" :prompt))) (defvar *default-point-color* nil) (defvar *default-point-fill?* t) (defvar *default-axis-color* nil) (defvar *default-bar-color* nil) (defvar *default-bar-fill?* nil) (defvar *default-pie-color* nil) (defvar *default-pie-fill?* t) (defvar *default-curve-color* nil) (defvar *default-label-color* nil) (defvar *default-slider-color* nil) (defvar *default-highlight-color* wb:*magenta-color*) (defvar *control-button-color* wb:*default-canvas-background-color*) (defvar *control-button-bg-color* nil) (defvar *default-highlight-operation* :boole-xor) (defvar *auto-draw-plot?* t) (defvar *auto-draw-view?* nil) (defvar *point-symbol-types* ) (setq *point-symbol-types* '(:box :circle :cross :diamond :star :triangle :poly-star)) (defvar *default-point-size*) (setq *default-point-size* 4) (defvar *default-point-symbol* :box ) (defvar *default-label-font* wb:*small-graphics-font*) (defvar *default-menu-font* wb:*very-small-graphics-font*) (defun sqr (x) (* x x)) (defun inverse(x) (/ 1.0 x)) (defvar *variable-transforms* ) (setq *variable-transforms* '( sqr identity sqrt log inverse :prompt)) (defvar *variable-summaries* ) (setq *variable-summaries* '( mean median sd iqr :prompt)) (defvar *default-brush-width* 16) (defvar *default-brush-height* 16) (defvar *view-fonts* (list wb:*very-small-graphics-font* wb:*small-graphics-font* wb:*normal-graphics-font* wb:*large-graphics-font*)) (defvar *default-window-region* NIL ;;(make-region 10 300 10 300) "Set this to nil for and make-view-window queries user for window location. ~ Otherwise set to a region where the window will appear.") (defun set-up-default-window-region (&optional (region (make-region 10 300 10 300))) (setf *default-window-region* region)) (defun new-font-size (old-font size) (let ((font (wb:copy-canvas-font old-font)) (old-size (wb:canvas-font-size old-font))) (if (eq size :bigger) (setq size (+ 2 old-size)) (if (eq size :smaller) (setq size (- old-size 2)))) (if (numberp size) (wb:set-canvas-font-size font size)) font)) (defvar *default-data-eq* #'eq-dataset) (defvar *simple-view-menu-list* '((ARROW "Arrow") (LINE-WMENU "line" ) (ORIENTED-LINE-WMENU "oriented-line" ) (LABEL "label") (POINT-SYMBOL "point-symbol") (RECTANGLE "rectangle") (PIE "pie") (TEXT-VIEW "text-view") (FUNCTION-VIEW "function-view"))) (defun color-to-string(color) (cond ((null color) "default") ((wb::colorp color) (cond ((wb:eq-colors color wb:*red-color*) "red") ((wb:eq-colors color wb:*blue-color*) "blue") ((wb:eq-colors color wb:*green-color*) "green") ((wb:eq-colors color wb:*yellow-color*) "yellow") ((wb:eq-colors color wb:*magenta-color*) "magenta") ((wb:eq-colors color wb:*black-color*) "black") ((wb:eq-colors color wb:*gray-color*) "gray") ((wb:eq-colors color wb:*light-gray-color*) "light gray") ((wb:eq-colors color wb:*dark-gray-color*) "dark-gray") ((wb:eq-colors color wb:*white-color*) "white") (t "unknown"))) (t (cond ((wb:eq-patterns color wb:*black-shade*) "black") ((wb:eq-patterns color wb:*gray-shade*) "gray") ((wb:eq-patterns color wb:*light-gray-shade*) "light gray") ((wb:eq-patterns color wb:*dark-gray-shade*) "dark-gray") ((wb:eq-patterns color wb:*white-shade*) "white") (t "unknown"))))) (defvar *default-draw-rate* 150 "The approximate number of frames per second in moving views")
6,043
Common Lisp
.l
141
35.531915
106
0.582377
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
592fb20398f0e5d630124174a106893a41a4a2df73cb14e1d71243ca1f735b5c
33,237
[ -1 ]
33,238
view-generics.lsp
rwoldford_Quail/source/views/views-general/view-generics.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; view-generics.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for ;;; interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(view-mixin add-mixin-to-view remove-mixin-from-view view bounding-region-of viewed-object-of subviews-of sub-view-locns-of visible-subviews-p viewports-of select-sub-view-locn construct-sub-views place-subview set-bounding-region compute-bounding-region init-position-subviews map-to-viewport map-subviews-to-viewport subviews-of-type compute-sub-viewports draw-view erase-view remove-view remove-subview invert-view highlight-view downlight-view selected-p reshape-viewport distance-to-location which-subview remap-to-viewports remap-sub-to-viewports move-subview add-subview move-view copy-image draw-viewport reposition-view describe-view describe-viewed-object short-description description-string inspect-view inspect-viewed-object change-bounding-region clip&draw print-viewed-object select-view deselect-view deselect-all toggle-select-view set-aspect-ratio list-subviews set-view-font smallest-bounding-region reshape-sub-viewports constrain-bounds subview-position-region use-x-axis-p use-y-axis-p sub-views-of subview-locns-of view-title-string ))) (defclass view-mixin (single-draw-style-mixin button-mixin linkable-bounds-mixin) () (:documentation "This class gathers together mixins for the basic view.")) (defun add-mixin-to-view (super) "Add super to the front of the supers list of the ~ class view-mixin. The value of the argument super ~ must be a symbol naming the class to be added." (let (supers) (setf supers (cons super (loop for s in (qk::class-direct-superclasses (find-class 'view-mixin)) collect (class-name s)) )) (eval `(defclass view-mixin ,supers () (:documentation "A class which gathers the many different mixins which together ~ define a view-mixin. It is the sole super class of view."))) ) ) (defun remove-mixin-from-view (super) "Removes super from the supers list of the ~ class view-mixin. The value of the argument super ~ must be a symbol naming the class to be removed." (let (supers) (setf supers (remove super (loop for s in (qk::class-direct-superclasses (find-class 'view-mixin)) collect (class-name s)) )) (eval `(defclass view-mixin ,supers () (:documentation "A class which gathers the many different mixins which together ~ define a view-mixin. It is the sole super class of view."))) ) ) (defclass view (view-mixin) ((bounding-region :initarg :bounding-region :initform nil :accessor bounding-region-of :documentation "A region in the local coordinates of view used to define its bounds") (viewed-object :initarg :data :initarg :viewed-object :initform nil :accessor viewed-object-of :documentation "Object being viewed") (maps-to-viewports :initform nil :accessor maps-to-viewports-of :documentation "A list of viewing transforms, where the ith transform maps the local coordinates of VIEW to those of its ith VIEWPORT") (parent-viewports :initform nil :accessor parent-viewports-of :documentation "The VIEWPORTs of parent views of self") (viewports :initform nil :accessor viewports-of :documentation "The ith VIEWPORT defines the extent of VIEW in the ith PARENT-VIEWPORT, i.e. it is obtained by mapping the BOUNDING-REGION of VIEW onto VIEWPORT")) (:documentation "The basic view") (:default-initargs :initform-fn nil)) (defgeneric set-bounding-region (view &key region pretty? ignore-x? ignore-y? &allow-other-keys) (:documentation " Sets bounding-region to region , if non-nil, ~ or (compute-bounding-region self). ~ If pretty? is non-nil the view may expand the ~ bounding region to cover a 'pretty' region ~ If ignore-x? is non-nil the x bounds view remain unchanged, ~ similarly ignore-y?")) (defgeneric compute-bounding-region (view ) (:documentation "Computes the bounding region of view")) (defgeneric construct-sub-views (view &key &allow-other-keys) (:documentation "Constructs sub-views of view")) (defgeneric place-subview (view subview locn ) (:documentation " Places subview at region locn in self. ~ Adds subview to self if not already present.")) (defgeneric map-to-viewport (view &optional viewport) (:documentation "Maps self to viewport. ~ Viewport may be a new viewport for self. ~ If viewport is nil, map self to all viewports. ")) (defgeneric map-subviews-to-viewport (view &optional viewport subviews) (:documentation "Maps subviews to viewport. ~ If subviews is nil, map all subviews of self. ~ If viewport is nil, map subviews to all viewports. ")) ;;;---------------------------------------------------------------------------------- (defgeneric draw-view (view &key viewport &allow-other-keys) (:documentation "Draw the view. ~ If viewport is nil draw in all viewports")) (defgeneric erase-view (view &key viewport &allow-other-keys) (:documentation "Erase the view ~ If viewport is nil erase in all viewports")) (defgeneric remove-view (view &key viewport &allow-other-keys) (:documentation "Removes the view (permanently) from viewport ~ If viewport is not provided, view is removed everywhere ~ Surgery is performed on the view hierarchy.")) (defgeneric remove-subview (view subview ) (:documentation " Removes the subview (permanently) from self ~ redrawing self everywhere ~ Surgery is performed on the view hierarchy ")) (defgeneric invert-view (view &key viewport &allow-other-keys) (:documentation "invert the view. ~ If viewport is nil invert in all viewports")) (defgeneric highlight-view (view &key viewport &allow-other-keys) (:documentation "highlight the view. ~ If viewport is nil highlight in all viewports")) (defgeneric downlight-view (view &key viewport &allow-other-keys) (:documentation "downlight the view. ~ If viewport is nil downlight in all viewports")) (defgeneric selected-p (view viewport location) (:documentation "Is view selected with mouse at location? ~ default looks to see if location is in viewport ")) (defgeneric reshape-viewport (view viewport &key new-location transform draw? &allow-other-keys) (:documentation "only one of transform or new-location should be provided")) (defgeneric distance-to-location (view viewport location) (:documentation "Computes a distance from viewport of view to location")) (defgeneric which-subview (view viewport location) (:documentation "Returns the view, its viewport its parent and the ~ parent's viewport at location as multiple values. ")) (defgeneric remap-to-viewports (view &key erase? &allow-other-keys) (:documentation "Recomputes viewports and redraws")) (defgeneric remap-sub-to-viewports (view subview &key erase? &allow-other-keys) (:documentation "Recomputes viewports of subviews and redraws")) (defgeneric move-subview (view subview new-region) (:documentation " Moves subview to new-region (in local coords of self). ~ New-region must be contained in the bounding-region of self")) (defgeneric add-subview (view subview new-region) (:documentation "Adds subview to self at position new-region (in coords of self).~ Subview must be a legal subview of view to be added.~ If subview is already in self, it is moved to new-region.")) (defgeneric move-view (view &key viewport new-location &allow-other-keys) (:documentation "Moves self to new-location (in coords of viewport).~ New-location must be contained in the viewport of self's parent.~ Moves self within the viewport of parent.")) (defgeneric copy-image (view &key viewport new-location &allow-other-keys) (:documentation "Copies self to new-location (in screen coords).~ If new-location is contained in the viewport ~ of self's parent, this is the same as move-view.")) (defgeneric reposition-view (view &key default-positions &allow-other-keys) (:documentation "Performs initial-layout.")) (defgeneric describe-view (view )) (defgeneric describe-viewed-object (view )) (defgeneric short-description (view )) (defgeneric description-string (view )) (defgeneric inspect-view (view)) (defgeneric inspect-viewed-object (view)) (defgeneric print-viewed-object (view)) (defgeneric change-bounding-region (view region &key &allow-other-keys) (:documentation "Sets bounding-region of self to region.~ and redraws everywhere.~ If ignore-x? is non-nil the x bounds view remain unchanged, ~ similarly ignore-y?.")) (defgeneric select-view (view) (:documentation "Adds to *selected-views*")) (defgeneric deselect-view (view) (:documentation "Removes from to *selected-views*")) (defgeneric toggle-select-view (view)) (defgeneric set-aspect-ratio (view &key viewport ratio draw? &allow-other-keys) (:documentation "Sets the width/height ratio of viewport to ratio")) (defgeneric list-subviews (view &key test &allow-other-keys) (:documentation "Lists subviews satisfying predicate test.~ Test could be a list, where entry i corresponds to subview i.~ Subviews with non-null test values are returned.")) (defgeneric init-position-subviews (view &key &allow-other-keys)) (defgeneric set-view-font (label &key name size style &allow-other-keys) (:documentation "Sets the font of the label to use name, size and style.~ Null values are ignored.~ (:see-also~ (wb:canvas-font-names :function)~ (wb:canvas-font-styles :function)~ (wb:canvas-make-font :function))~ ")) (defgeneric constrain-bounds (view &key draw? &allow-other-keys) (:documentation "Constrains the bounds of subviews of view.~ Redraws when draw? is non-nil")) (defgeneric subview-position-region (view ) (:documentation "Region in which subviews are positioned.~ Default is bounding region")) (defgeneric use-x-axis-p (view) (:documentation "Does it make sense for this view to have an x axis?")) (defgeneric use-y-axis-p (view) (:documentation "Does it make sense for this view to have a y axis?")) (defgeneric view-title-string (view) (:documentation "Returns a string used for a title"))
12,575
Common Lisp
.l
243
41.55144
140
0.632884
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
752def1219674df7b009f91f5e54bf60d53e9b5481ea80b89a42fb6d4b6920a2
33,238
[ -1 ]
33,239
button-mixin.lsp
rwoldford_Quail/source/views/views-general/button-mixin.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; button-mixin.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, ;;; a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*selected-views* selected-view selected-views *selected-subviews-only* button-mixin left-fn-of left-menu middle-menu right-menu ;;(setf left-fn-of) remake-menu remake-menus left-button-fn middle-button-fn right-button-fn shift-left-button-fn shift-middle-button-fn shift-right-button-fn ctrl-left-button-fn ctrl-middle-button-fn ctrl-right-button-fn get-menu-items menu-properties update-menu-items default-right-items style-menu-items ))) ;;;---------------------------------------------------------------------------------- (defvar *selected-subviews-only* t "when this is t menu operations for changing drawing styles ~ operate on highlit subviews only") (setq *selected-subviews-only* :if-highlit) (defclass button-mixin () ((left-fn :accessor left-fn-of :initarg :left-fn :initform (list #'default-left-fn :viewport )) (left-menu :allocation :class :initform nil) (middle-menu :allocation :class :initform nil) (right-menu :allocation :class :initform nil) (ctrl-left-menu :allocation :class :initform nil) (ctrl-middle-menu :allocation :class :initform nil) (ctrl-right-menu :allocation :class :initform nil) )) (defgeneric remake-menu (button-mixin slot-name &optional items) (:documentation "Remake the menu slot-name with items (if present) ~ or the default")) (defgeneric remake-menus (button-mixin) (:documentation "Remake the menus")) (defgeneric left-button-fn (button-mixin &key viewport &allow-other-keys ) (:documentation "Invoked when left button is depressed on view")) (defgeneric right-button-fn (button-mixin &key viewport &allow-other-keys ) (:documentation "Invoked when right button is depressed on view")) (defgeneric middle-button-fn (button-mixin &key viewport &allow-other-keys) (:documentation "Invoked when middle button is depressed on view")) (defgeneric ctrl-left-button-fn (button-mixin &key viewport &allow-other-keys ) (:documentation "Invoked when ctrl-left button is depressed on view")) (defgeneric ctrl-middle-button-fn (button-mixin &key viewport &allow-other-keys) (:documentation "Invoked when ctrl-middle button is depressed on view")) (defgeneric ctrl-right-button-fn (button-mixin &key viewport &allow-other-keys) (:documentation "Invoked when ctrl-right button is depressed on view")) (defgeneric shift-left-button-fn (button-mixin &key viewport &allow-other-keys ) (:documentation "Invoked when shift-left button is depressed on view")) (defgeneric shift-middle-button-fn (button-mixin &key viewport &allow-other-keys ) (:documentation "Invoked when shift-middle button is depressed on view")) (defgeneric shift-right-button-fn (button-mixin &key viewport &allow-other-keys ) (:documentation "Invoked when shift-right button is depressed on view")) (defgeneric default-left-fn (self &key viewport &allow-other-keys) (:documentation "left button fn can be different from class to class.")) (defgeneric get-menu-items (button-mixin menu-name) (:documentation "Return the menu items for menu-name")) (defgeneric menu-properties (button-mixin menu-name) (:documentation "This method returns an alist to be placed as properties ~ on the menu associated with menu-name. ~ Whenever the associated menu is requested its properties are ~ checked with the result of menu-properties and a new menu is created ~ if the properties differ.")) (defgeneric update-menu-items (button-mixin menu-name) (:documentation "Updates the menu assiciated with menu-name. ~ Called before the menu is popped up")) ;;;---------------------------------------------------------------------------------- (defmethod set-color-style(self &rest keys &key highlit? color &allow-other-keys) (declare (ignore keys)) (if (eq color :prompt) (setq color (wb::prompt-user-for-color))) (set-drawing-style self :color color :highlit? highlit?)) (defun color-menu-items () (declare (special *color-menu-list* *shade-menu-list* *selected-subviews-only*)) (loop for c in (if (wb:color-device-p) *color-menu-list* *shade-menu-list*) collect (list (car c) `(set-color-style :color ,(cadr c) :highlit? *selected-subviews-only*)))) (defun font-menu-items () (let ((font-name (loop for f in (wb:canvas-font-names) collect (list f `(set-view-font :name ,f)))) (font-style (loop for f in (wb:canvas-font-styles) collect (list f `(set-view-font :style ,f)))) (font-size '(("smaller" (set-view-font :size :smaller )) ("larger" (set-view-font :size :bigger )) ("Prompt" (set-view-font :size :prompt))))) `(("FontSize" nil "" :sub-items ,font-size ) ("FontName" nil "" :sub-items ,font-name ) ("FontStyle" nil "" :sub-items ,font-style ) ))) (defgeneric style-menu-items (self)) #| (defun default-right-items () (let ((layers (append (loop for (string sym) in (view-menu-list 'view) collect `(,string (layer-view ,sym :viewport))) `(("Selected" (layer-selected-view :viewport )))))) `(;;("Link" (link-view )) ("Link" (link-selected-views )) ("Unlink" (unlink-selected-view)) ("Cut" (remove-view :viewport )) ("Paste" nil "" :sub-items ,layers) ("Drag" (move-view :viewport )) ("DragCopy" (copy-image :viewport )) ("Recompute" (reposition-view :viewport)) ("Clone" (copy-view :viewport :draw? t)) ("CloneFn" (clone-view-fn-prompt :viewport)) ("Inspect" (inspect)) ))) |# (defun default-right-items () (let ((layers `(("Selected" (layer-selected-view :viewport ))))) `(("Link" ,#'(lambda(v) (if (typep v 'linkable-mixin) (setf (linkable-view-p v) t)) (link-selected-views v))) ("Unlink" (unlink-top-views)) ("Cut" (remove-view :viewport )) ("Paste" nil "" :sub-items ,layers) ("Move" (move-view :viewport )) ("Copy image" (copy-image :viewport )) ("Recompute" (reposition-view :viewport)) ("Copy" (copy-view :viewport :draw? t)) ("CloneFn" (clone-view-fn-prompt :viewport)) ("Inspect" (inspect)) ))) (defvar *selected-views* nil) (defvar *selected-view* nil) (defun selected-views () *selected-views*) (defun set-selected-views(sel) (setq *selected-views* sel)) (defun selected-view () (or *selected-view* (car *selected-views*))) (defun highlighted-views() (let ((all (loop for v in *selected-views* collect v append (linked-views-of v)))) (loop for v in all when (any-highlight? v) collect v))) (defmethod remake-menu ((self button-mixin) slot-name &optional items) (setf (slot-value self slot-name) (or items (get-menu-items self slot-name)))) (defmethod remake-menu :before ((self button-mixin) slot-name &optional items) "Releases the menu space." (declare (ignore items)) (if (wb::menu-p (slot-value self slot-name)) (wb::release-menu-space (slot-value self slot-name)))) (defmethod remake-menus ((self button-mixin)) ;; for remaking the menus ;;(remake-left-menu self) (remake-menu self 'middle-menu) (remake-menu self 'right-menu) (remake-menu self 'ctrl-left-menu) (remake-menu self 'ctrl-middle-menu) (remake-menu self 'ctrl-right-menu)) (defun button-mixin-when-selected-fn (item menu mouse-button) (declare (ignore menu mouse-button)) (second item )) ;;; ;;; Added a cache for pop-up menus. Machines are now fast enough that we don't ;;; need to hold onto them all and this eliminates some storage (especially ;;; important where there is an upper bound on the number of ``open-streams'' ;;; as in acl 3.02). ... rwo May 1998. ;;; (defvar *button-mixin-menu-cache* NIL "An association-list of cached pop-up menus for button-mixin." ) (defvar *button-mixin-menu-cache-size* 5 "The number of pop-up menus that are to be cached.") (defun button-mixin-cache-size () "Returns the size of the cache of pop-up menus for button mixins." *button-mixin-menu-cache-size*) (defun set-button-mixin-cache-size (size) "Sets the size of the cache of pop-up menus for button mixins." (setf *button-mixin-menu-cache-size* size)) (defun add-menu-to-button-mixin-cache (menu cache-key) (unless (assoc cache-key *button-mixin-menu-cache*) (if (= (length *button-mixin-menu-cache*) (button-mixin-cache-size)) (let* ((last-cache (car (last *button-mixin-menu-cache*))) (last-key (car last-cache)) (obj (first last-key)) (slot-name (second last-key)) ) (setf *button-mixin-menu-cache* (butlast *button-mixin-menu-cache*)) (setf (slot-value obj slot-name) NIL) (wb::release-menu-space (cdr last-cache)) )) (push (cons cache-key menu) *button-mixin-menu-cache*))) (defmethod menu-of ((self button-mixin) slot-name) (if (need-new-menu-p self slot-name) (remake-menu self slot-name)) (let ((it (slot-value self slot-name)) m) (when (and it (not (wb:menu-p it))) (setq m (wb:make-menu :items it :when-selected-fn #'button-mixin-when-selected-fn )) (loop for p in (menu-properties self slot-name) do (wb:put-menu-prop m (car p) (cdr p))) (add-menu-to-button-mixin-cache m (list self slot-name)) (setf (slot-value self slot-name) m))) (update-menu-items self slot-name) (slot-value self slot-name)) #| (defmethod menu-of ((self button-mixin) slot-name) (if (need-new-menu-p self slot-name) (remake-menu self slot-name)) (let ((it (slot-value self slot-name)) m) (when (and it (not (wb:menu-p it))) (setq m (wb:make-menu :items it :when-selected-fn #'button-mixin-when-selected-fn )) (loop for p in (menu-properties self slot-name) do (wb:put-menu-prop m (car p) (cdr p))) (setf (slot-value self slot-name) m))) (update-menu-items self slot-name) (slot-value self slot-name)) |# (defmethod menu-choose-item ((self button-mixin) slot-name viewport ) (if (typep self 'simple-view) (invert-view self :viewport viewport)) (let* ((m (menu-of self slot-name)) (choice (if m (wb:menu m)))) (if (typep self 'simple-view) (invert-view self :viewport viewport)) (if choice (apply-choice self choice viewport )))) (defmethod apply-choice ((self button-mixin) choice &optional viewport ) (if (listp choice) (if (not (or (eq (first choice) 'setq) (eq (first choice) 'setf))) (let* ((f (car choice)) ; assume a function followed by args (args (mapcar #'(lambda(x) (if (and (symbolp x) (boundp x)) (eval x) x)) (cdr choice))) (vlist (member :viewport args)) (target-fn (second (member :target args))) target) (unless (functionp f) (setq f (symbol-function f))) (when target-fn ;;(remf args :target) (setq args (delete :target args)) (setq args (delete target-fn args)) (unless (functionp target-fn) (setq target-fn (symbol-function target-fn))) (setq target (funcall target-fn self)) (if vlist (setq viewport (select-viewport target viewport)))) (if vlist (push viewport (cdr vlist))) (apply f (or target self) args)) (eval choice)) (funcall (if (functionp choice) choice (symbol-function choice)) self ))) (defmethod default-left-fn ((self button-mixin) &key &allow-other-keys) ;; left button fn can be different from instance to instance (select-one self) (short-description self) ) (defmethod left-button-fn ((self button-mixin) &key viewport ) (let ((lbf (left-fn-of self))) (if lbf (apply-choice self lbf viewport ) (menu-choose-item self 'left-menu viewport )))) (defmethod right-button-fn ((self button-mixin) &key viewport ) (menu-choose-item self 'right-menu viewport )) (defmethod middle-button-fn ((self button-mixin) &key viewport ) (menu-choose-item self 'middle-menu viewport )) (defmethod ctrl-left-button-fn ((self button-mixin) &key viewport ) (menu-choose-item self 'ctrl-left-menu viewport )) (defmethod ctrl-middle-button-fn ((self button-mixin) &key viewport ) (declare (ignore viewport )) (inspect-viewed-object self) ) (defvar *display-viewed-data-viewport* nil) (defmethod ctrl-right-button-fn ((self button-mixin) &key viewport ) (declare (ignore viewport ) (special *display-viewed-data-viewport* )) (if (and *display-viewed-data-viewport* (active-viewport-p *display-viewed-data-viewport*)) (let ((w (window-of *display-viewed-data-viewport*))) (wb:canvas-clear w) (remove-view-from-window w :viewport *display-viewed-data-viewport*) (display-viewed-object self :as-dataset? t :draw? t :signposts? nil :viewport *display-viewed-data-viewport*)) (let* ((r (view-region wb:*default-canvas-region*)) (right (min (+ (wb:screen-mouse-x) (width-of r)) (- (wb::window-max-width) 15) )) (top (min (+ (wb:screen-mouse-y) (height-of r)) (- (wb::window-max-height) 30))) (w (make-view-window :left (max 0 (- right (width-of r))) :bottom (max 0 (- top (height-of r))) :right right :top top)) (vp (make-viewport w))) (display-viewed-object self :as-dataset? t :draw? t :signposts? nil :viewport vp)))) (defmethod shift-left-button-fn ((self button-mixin) &key viewport ) (declare (ignore viewport )) ;;(toggle-select-view self) (select-view self) (short-description self)) (defmethod shift-middle-button-fn ((self button-mixin) &key viewport) ;; intersection ;; combination ;; turns off the parts of highlit views which are not linked to self (declare (ignore viewport )) (short-description self) (when *selected-views* (let ((old-views (remove-duplicates (highlighted-views)))) (with-update-style-cache (loop for v in old-views do (set-highlight-style v nil :not-from self :draw-links? nil)))) (set-selected-views (list self)))) (defmethod shift-right-button-fn ((self button-mixin) &key viewport ) ;; subtract (declare (ignore viewport )) (short-description self) ;; (when (any-highlight? self) (with-update-style-cache (set-highlight-style self nil) (set-selected-views (delete self *selected-views*)))) ;; slight change 6-6-95 (defmethod temporary-left-fn ((self button-mixin) temp-fn current-viewport) ;; temp-fn is any acceptable 2nd argument to apply-choice ;; with click in viewport (declare (ignore current-viewport)) (let ((old-fn (left-fn-of self)) (current-time (get-universal-time)) (wait-time 6) new-left-fn) (setf new-left-fn #'(lambda (v &key viewport ) (declare (ignore v)) (if (<= (- (get-universal-time) current-time) wait-time) (apply-choice self temp-fn viewport ) ) (setf (left-fn-of self) old-fn))) (setf (left-fn-of self) (list new-left-fn :viewport )))) (defmethod get-menu-items ((self button-mixin) (slot-name (eql 'ctrl-left-menu))) `(("Inspect viewed object" (inspect-viewed-object)) ("Display viewed-object" (display-viewed-object) "" :sub-items (("Display" (display-viewed-object :signposts? NIL)) ("Display with signposts" (display-viewed-object :signposts? T)))) ) ) (defmethod get-menu-items ((self button-mixin) (slot-name (eql 'ctrl-middle-menu))) `(("Inspect viewed object" (inspect-viewed-object)) ("Display viewed-object" (display-viewed-object) "" :sub-items (("Display" (display-viewed-object :signposts? NIL)) ("Display with signposts" (display-viewed-object :signposts? T)))) ) ) (defmethod get-menu-items ((self button-mixin) (slot-name (eql 'ctrl-right-menu))) `(("Inspect viewed object" (inspect-viewed-object)) ("Display viewed-object" (display-viewed-object) "" :sub-items (("Display" (display-viewed-object :signposts? NIL)) ("Display with signposts" (display-viewed-object :signposts? T)))) ) ) (defmethod get-menu-items ((self button-mixin) (slot-name (eql 'middle-menu))) ) (defmethod add-menu-items ((self button-mixin) add-items items) (if (eq add-items items) items (append (loop for menu-item in add-items for label = (car menu-item) unless (member label items :test #'string-equal :key #'car) collect menu-item) items))) (defmethod get-menu-items :around ((self button-mixin) (slot-name (eql 'middle-menu))) (add-menu-items self (style-menu-items self) (call-next-method))) (defmethod style-menu-items ((self button-mixin))) (defmethod style-menu-items :around ((self button-mixin)) (add-menu-items self `(("Highlight?" (toggle-select-view)) ("Color" nil "" :sub-items ,(color-menu-items)) ("Invisible?" (set-drawing-style :invisible? :toggle :highlit? *selected-subviews-only* ))) (call-next-method))) (defmethod get-menu-items ((self button-mixin) (slot-name (eql 'right-menu))) (default-right-items)) (defmethod get-menu-items :around ((self button-mixin) (slot-name (eql 'right-menu))) (let ((result (call-next-method))) (add-menu-items self (default-right-items) result))) (defmethod menu-properties ((self button-mixin) slot-name) ;; this method can be specialized to return an alist ;; the items on the alist are placed as properties on the menu ;; accessed by slot-name ;; Whenever the associated menu is requested its properties are ;; checked with the result of menu-properties and a new menu is created ;; if the properties differ (declare (ignorable slot-name)) ;(declare (ignore slot-name)) ; 29JUL2023 ) (defmethod menu-properties :around ((self button-mixin) (slot-name (eql 'middle-menu))) ;; the items on the alist are placed as properties on the menu ;; accessed by slot-name ;; most middle menus use color/b+w depending on whether color is available ;; and being used (declare (ignorable slot-name)) ;(declare (ignore slot-name)) ; 29JUL2023 (append (call-next-method) (list (cons :use-color (wb:color-device-p))))) (defmethod need-new-menu-p ((self button-mixin) slot-name) (let* ((m (slot-value self slot-name))) (or (null m) (and (wb:menu-p m) (loop for p in (menu-properties self slot-name) thereis (not (eql (cdr p) (wb:get-menu-prop m (car p))))))))) (defmethod update-menu-items ((self button-mixin) slot-name) (declare (ignorable slot-name)) ;(declare (ignore slot-name)) ; 29JUL2023 ) (defmethod update-menu-items :before ((self button-mixin) (slot-name (eql 'middle-menu))) (let* ((m (slot-value self slot-name))) (wb:check-menu-item m "Highlight?" (draw-style self :highlight?)) (wb:check-menu-item m "Invisible?" (draw-style self :invisible?)) (if (and m (has-draw-style-p self :fill?)) (wb:check-menu-item m "Fill?" (draw-style self :fill?)) )))
22,398
Common Lisp
.l
468
37.673077
113
0.589307
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3dd4ded7cccee769ca7825d85303e33bfb1d2baf71e5f8d5ca02b91116b7f0ee
33,239
[ -1 ]
33,240
change-cases.lsp
rwoldford_Quail/source/views/dview-def/change-cases.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; change-cases.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) ;;;---------------------------------------------------------------------------------- (defmethod case-links-of ((self d-view)) (if (link-cases-p self) (loop for v in (link-bounds-of self) when (and (typep v 'd-view) (link-cases-p v)) collect v) (list self))) (defmethod case-links-of ((self 1d-view)) (if (link-cases-p self) (loop for v in (if (eq (orientation-of self ) :horizontal) (link-bounds-x-of self) (link-bounds-y-of self)) when (and (typep v 'd-view) (link-cases-p v)) collect v) (list self))) ;;=================================================================================================== (defmethod new-case-status ((self d-view) cases status &key ) (declare (ignore cases status)) (new-sub-views self :reposition? t) ) (defmethod new-case-status :before ((self d-view) cases status &key ) (let ((case-status (case-status-of self)) (new-status-fn (if (ignore-status-p status) #'(lambda(old) (if (invalid-status-p old) :invalid-ignore :ignore) ) #'(lambda(old) (if (invalid-status-p old) nil t) )))) (if (eq cases (cases-of self)) (loop for s in case-status for new = (funcall new-status-fn s) for i upfrom 0 when new do (setf (elt case-status i) new)) (loop with new for vo in (cases-of self) for s in case-status for i upfrom 0 when (and (or (member vo cases :test #'eq-dataset) (and (identifier-of vo) (member (identifier-of vo) cases :test #'eq-identifiers))) (setq new (funcall new-status-fn s) )) do (setf (elt case-status i) new))))) (defmethod new-case-status :around ((self d-view) cases status &key (rescale? t) (draw? t ) ) (declare (ignore cases status)) (if draw? (erase-view self)) (call-next-method) (if rescale? (reset-bounding-region self :draw? nil )) (if draw? (remap-to-viewports self :erase? nil :draw? draw?))) (defmethod activate-cases ((self d-view) cases &rest args &key ) (apply #'change-case-status self cases t args)) (defmethod deactivate-cases ((self d-view) cases &rest args &key ) (apply #'change-case-status self cases :ignore args)) (defmethod activate-all-cases ((self d-view) &rest args &key ) (apply #'change-case-status self (cases-of self) t args)) (defmethod change-case-status :around ((self d-view) cases status &rest args &key (link? t)) (cond ((eq cases :selected) (setq cases (loop for v in *selected-views* append (list-viewed-elements v)))) ((eq cases :unselected) (let ((sel-cases (loop for v in *selected-views* append (list-viewed-elements v)))) (setq cases (loop for c in (cases-of self) unless (member c sel-cases :test #'eq-dataset) collect c)))) (t nil)) (if cases (if (or (eq link? t) (and (typep link? 'view) (not (eq self link?)))) (apply #'call-next-method self cases status args) (if (null link?) (apply #'new-case-status self cases status args) (apply #'new-case-status self cases status :draw? nil args))))) (defmethod change-case-status ((self d-view) cases status &key (rescale? t) (draw? t )) (new-case-status self cases status :rescale? rescale? :draw? draw? )) (defmethod change-case-status ((self 2d-view) cases status &key (rescale? t) (draw? t )) (flet ((pass-to-links (draw? ) (loop for v in (case-links-of self) do (new-case-status v cases status :draw? draw? :rescale? nil) (if rescale? (set-bounding-region v))))) (if rescale? (with-constrained-extents self draw? (pass-to-links nil )) (pass-to-links draw?)))) (defmethod change-case-status ((self 1d-view) cases status &key (rescale? t) (draw? t )) (flet ((pass-to-links (draw? ) (loop for v in (case-links-of self) do (new-case-status v cases status :draw? draw? :rescale? nil ) (if rescale? (set-bounding-region v)) ))) (if rescale? (with-constrained-extents self draw? (pass-to-links nil )) (pass-to-links draw?))))
5,625
Common Lisp
.l
127
33.370079
102
0.488609
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
850b15ead6f92b11c1c1e52c11448ff605cce42675dce5c4ed0f11545236d777
33,240
[ -1 ]
33,241
d-view-mixins.lsp
rwoldford_Quail/source/views/dview-def/d-view-mixins.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; d-view-mixins.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views ) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(data-extract-mixin ncases data-menu-item-mixin var-menu-items case-menu-items ))) (defclass data-extract-mixin() ((variates :initarg :variates :initform #'list-variates) (dataset :initarg :data :initform nil) (cases :initarg :subjects :initarg :cases :initform #'list-cases )) (:default-initargs :labels #'identifier-name :value-fn #'value-of )) (defclass data-menu-item-mixin() ()) (defgeneric var-menu-items (data-menu-item-mixin &key &allow-other-keys) ) (defmethod var-menu-items ((self data-menu-item-mixin) &key target) (declare (ignore target))) (defgeneric case-menu-items (data-menu-item-mixin &key &allow-other-keys) ) (defmethod case-menu-items ((self data-menu-item-mixin) &key target) (declare (ignore target))) #| (defun construct-viewed-object-list(data cases) "Returns a list of the viewed-objects.~ These are typically cases." (cond ((functionp cases) (funcall cases data)) ((list-of-datasets-p cases) cases) ((null data) nil) ((dataset-p data) (list-cases data)) (t (quail-error "Invalid subject argument ~A" cases)))) |# (defmethod dataset-of ((self data-extract-mixin)) (or (slot-value self 'dataset) (let ((v (viewed-object-of self))) (if (dataset-p v) (setf (slot-value self 'dataset) v))))) (defmethod variates-of ((self data-extract-mixin)) (let ((v (slot-value self 'variates)) c ans ) (cond ((listp v) v) ((setq ans (funcall v (dataset-of self))) (setf (slot-value self 'variates) ans)) ((and (setq c (car (cases-of self))) (dataset-p c) (typep v 'standard-generic-function) (compute-applicable-methods v (list c))) (setf (slot-value self 'variates) (funcall v c))) (t (setf (slot-value self 'variates) nil))))) (defmethod cases-of ((self data-extract-mixin)) (let ((c (slot-value self 'cases))) (if (and c (listp c) (not (eql (car c) :by))) c (let ((d (dataset-of self))) (setf (slot-value self 'cases) (cond ((functionp c) (funcall c d)) ((and (listp c) (eql (car c) :by)) (funcall (data-subsets-fn (cdr c) ) d)) ((null d) nil) ((dataset-p d) (list-cases d)) (t nil))))))) (defmethod variate-names-of ((self data-extract-mixin)) "Returns a list of variate-names." (variate-names (variates-of self) )) (defun variate-names (vars) ;; returns a list of variate-names (loop for v in vars collect (cond ((numberp v) (format nil "var ~D" v)) ((typep v '(OR STRING CHARACTER SYMBOL)) (string v)) (t (format nil "~A" v)))))
3,772
Common Lisp
.l
93
31.946237
128
0.525978
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
34515ec84adead95894164a1c4f7b18bceb83e059c204f2d42cab0e01665cb0d
33,241
[ -1 ]
33,242
d-view-menus.lsp
rwoldford_Quail/source/views/dview-def/d-view-menus.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; d-view-menus.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1992 George Washington University ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(menu-variates-of))) (defgeneric menu-variates-of (d-view) (:documentation "Returns a list of the variates used in the variate menu.")) (defmethod menu-variates-of ((self d-view)) (variates-of self)) (defmethod get-menu-items :around ((self 2d-view) (slot-name (eql 'right-menu))) (let ((result (call-next-method)) (layers (append (loop for (string sym) in (view-menu-list '2d-view) collect `(,string (layer-view ,sym :viewport))) `(("FunctionView" (layer-view function-view :viewport)) ("Line" (layer-view line :viewport :slope :prompt :intercept :prompt)) ("LineSegment" (layer-view line-segment :viewport )) ("OrientedLine" nil "" :sub-items (("Horizontal" (layer-view oriented-line :viewport :orientation :horizontal :intercept :prompt )) ("Vertical" (layer-view oriented-line :viewport :orientation :vertical :intercept :prompt)))) ("Selected" (layer-selected-view :viewport )))))) (add-menu-items self result `(("Paste" nil "" :sub-items ,layers))))) (defmethod get-menu-items :around ((self 1d-view) (slot-name (eql 'right-menu))) (let ((result (call-next-method)) (layers (append (loop for (string sym) in (view-menu-list '1d-view) collect (list string (list 'layer-view sym :viewport))) `(("FunctionView" (layer-view function-view :viewport)) ("Line" (layer-view line :viewport :slope :prompt :intercept :prompt)) ("OrientedLine" nil "" :sub-items (("Horizontal" (layer-view oriented-line :viewport :orientation :horizontal :intercept :prompt )) ("Vertical" (layer-view oriented-line :viewport :orientation :vertical :intercept :prompt)))) ("Selected" (layer-selected-view :viewport )))))) (add-menu-items self result `(("Paste" nil "" :sub-items ,layers))))) (defmethod get-menu-items :around ((self d-view) (slot-name (eql 'middle-menu))) (let* ((vm (var-menu-items self)) (cm (case-menu-items self)) (var-menu-items (if vm (append vm `(("-" nil) ("LinkVars?" (set-link-vars-p :toggle)))) `(("LinkVars?" (set-link-vars-p :toggle))))) (case-menu-items (if cm (append cm `(("-" nil) ("LinkCases?" (set-link-cases-p :toggle)))) `(("LinkCases?" (set-link-cases-p :toggle)))))) (add-menu-items self (call-next-method) `(("-" nil) ("Variables" nil "" :sub-items ,var-menu-items) ("Cases" nil "" :sub-items ,case-menu-items) ("-" nil) ("Flip-x" (set-flip-x-p :toggle :draw? t)) ("Flip-y" (set-flip-y-p :toggle :draw? t)))))) (defmethod case-menu-items ((self d-view) &key target) `( ("DeactivateSelected" nil "" :sub-items (("Rescale" (deactivate-cases :selected :rescale? t :target ,target)) ("NoRescale" (deactivate-cases :selected :rescale? nil :target ,target))) ) ("DeactivateUnSelected" nil "" :sub-items (("Rescale" (deactivate-cases :unselected :rescale? t :target ,target)) ("NoRescale" (deactivate-cases :unselected :rescale? nil :target ,target))) ) ("ActivateSelected" nil "" :sub-items (("Rescale" (activate-cases :selected :rescale? t :target ,target)) ("NoRescale" (activate-cases :selected :rescale? nil :target ,target)))) ("ActivateUnSelected" nil "" :sub-items (("Rescale" (activate-cases :unselected :rescale? t :target ,target)) ("NoRescale" (activate-cases :unselected :rescale? nil :target ,target)))) ("ActivateAll" nil "" :sub-items (("Rescale" (activate-all-cases :rescale? t :target ,target)) ("NoRescale" (activate-all-cases :rescale? nil :target ,target))) )) ) (defmethod update-menu-items :after ((self d-view) (slot-name (eql 'middle-menu))) (let* ((m-case (wb:get-menu-item (slot-value self slot-name) "Cases")) (m-var (wb:get-menu-item (slot-value self slot-name) "Variables")) ) (if m-case (wb:check-menu-item m-case "LinkCases?" (link-cases-p self))) (if m-var (wb:check-menu-item m-var "LinkVars?" (link-vars-p self))))) (defmethod change-variable-when-vars ((self d-view) &rest args) (if (has-variates-p self) (apply #'change-variable self args) )) (defun var-menu-item-list (vars key &key (names vars) target method) (let ((answer (loop for v in vars for vn in names collect `( ,(format nil "~(~A~)" vn) (,method ,key ,v :draw? t :target ,target ))))) (if (and answer (member key (list :transform :x-transform :y-transform :z-transform))) (append answer `(("Identity" (,method ,key nil :draw? t :target ,target)))) answer))) (defmethod var-menu-items ((self d-view) &key target (method 'change-variable-when-vars)) (let* (( vars (menu-variates-of self)) (projs (loop with n = (ncases self) for p in *projections* when (= n (projector-dim p)) collect p)) (var-list (var-menu-item-list vars :var :names (variate-names vars) :target target :method method )) (func-list (var-menu-item-list (variable-transform-list self) :function :target target :method method)) (trans-list (var-menu-item-list projs :transform :target target :method method :names (mapcar #'projector-name projs)))) `( ,(if vars `( "Var" nil "" :sub-items ,var-list)) ,(if func-list `( "Function" nil "" :sub-items ,func-list)) ,(if projs `( "Matrix" nil "" :sub-items ,trans-list) nil) ))) (defmethod menu-properties :around ((self d-view) (slot-name (eql 'middle-menu))) ;; middle menus for plots are remade when any of variates, projections ;; or functions change (let ((data (menu-variates-of self))) (append (list (cons :ncases (ncases self)) (cons :variates data) (cons :functions (variable-transform-list self)) (cons :projections *projections*)) (call-next-method)))) (defmethod variable-transform-list (self) (let ((f (x-func-of self))) (cond ((null f) *variable-transforms*) ((loop with f1 = (get-function f) for v in *variable-summaries* thereis (and (not (eql v :prompt) ) (equal f1 (get-function v)))) *variable-summaries*) (t *variable-transforms*)))) (defmethod var-menu-items ((self 2d-view) &key target (method 'change-variable-when-vars)) (let ((vars (menu-variates-of self)) (projs (loop with n = (ncases self ) for p in *projections* when (= n (projector-dim p)) collect p)) x-list y-list func-list-x func-list-y p-list-x p-list-y) (multiple-value-setq (x-list y-list) (values-list (loop with names = (variate-names vars) for v in (list :x :y) collect (var-menu-item-list vars v :names names :target target :method method)))) (multiple-value-setq (func-list-x func-list-y) (values-list (loop with tlist = (variable-transform-list self) for v in (list :x-function :y-function) collect (var-menu-item-list tlist v :target target :method method)))) (multiple-value-setq (p-list-x p-list-y) (values-list (loop with names = (mapcar #'projector-name projs) for v in (list :x-transform :y-transform) collect (var-menu-item-list projs v :names names :target target :method method)))) `( ,(if vars `( "X Select" nil "" :sub-items ,x-list)) ,(if func-list-x `( "X Function" nil "" :sub-items ,func-list-x)) ,(if projs `("X Matrix" nil "" :sub-items ,p-list-x) nil) ,(if (or vars func-list-x projs) `("-" nil)) ,(if vars `( "Y Select" nil "" :sub-items ,y-list)) ,(if func-list-y `( "Y Function" nil "" :sub-items ,func-list-y)) ,(if projs `("Y Matrix" nil "" :sub-items ,p-list-y) nil)))) (defmethod var-menu-items ((self 3d-view) &key target (method 'change-variable-when-vars)) (let ((vars (menu-variates-of self)) (projs (loop with n = (ncases self ) for p in *projections* when (= n (projector-dim p)) collect p)) x-list y-list z-list func-list-x func-list-y func-list-z p-list-x p-list-y p-list-z) (multiple-value-setq (x-list y-list z-list) (values-list (loop with names = (variate-names vars) for v in (list :x :y :z) collect (var-menu-item-list vars v :names names :target target :method method)))) (multiple-value-setq (func-list-x func-list-y func-list-z) (values-list (loop with tlist = (variable-transform-list self) for v in (list :x-function :y-function :z-function) collect (var-menu-item-list tlist v :target target :method method)))) (multiple-value-setq (p-list-x p-list-y p-list-z) (values-list (loop with names = (mapcar #'projector-name projs) for v in (list :x-transform :y-transform :z-transform) collect (var-menu-item-list projs v :names names :target target :method method)))) `(,(if vars `( "X Select" nil "" :sub-items ,x-list)) ,(if func-list-x `( "X Function" nil "" :sub-items ,func-list-x)) ,(if projs `("X Matrix" nil "" :sub-items ,p-list-x) nil) ,(if (or vars func-list-x projs) `("-" nil)) ,(if vars `( "Y Select" nil "" :sub-items ,y-list)) ,(if func-list-y `( "Y Function" nil "" :sub-items ,func-list-y)) ,(if projs `("Y Matrix" nil "" :sub-items ,p-list-y) nil) ,(if (or vars func-list-y projs) `("-" nil)) ,(if vars `( "Z Select" nil "" :sub-items ,z-list)) ,(if func-list-z `( "Z Function" nil "" :sub-items ,func-list-z)) ,(if projs `("Z Matrix" nil "" :sub-items ,p-list-z) nil))))
12,743
Common Lisp
.l
247
36.712551
97
0.499307
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
19cf08dadfe1a302d9bbb965bbd416660fbadf20fd88944bbf754ab9d818228b
33,242
[ -1 ]
33,243
text-link.lsp
rwoldford_Quail/source/views/dview-def/text-link.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; text-link.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(text-link))) (defmethod update-label-viewed-object ((self label) new) (declare (ignore new))) (defmethod text-link((self view) label &optional position) (declare (ignore position label))) (defmethod text-unlink((self view) label) (declare (ignore label))) (defmethod text-link((self d-view) (label label) &optional position) (setq position (cond ((numberp position) position) ((eq position :x) 0) ((eq position :y) 1) ((eq position :z) 2) (t nil))) (if position (setf (viewed-object-of label) (extract-variate (dataset-of self) (nth position (vars-of self))))) (if (null (text-links-of self)) (setf (text-links-of self) (make-list (length (coord-strings self))))) (if (and (numberp position) (< position (length (text-links-of self)))) (push label (elt (text-links-of self) position)) ;; (loop for position from 0 below (length (text-links-of self)) do (do ((position 0 (incf position))) ((= position (length (text-links-of self)))) (push label (elt (text-links-of self) position))))) (defmethod text-unlink((self d-view) label) (setf (text-links-of self) (loop for l in (text-links-of self) collect (delete label l)))) (defmethod update-text-link((self d-view) &optional position) (setq position (cond ((numberp position) position) ((eq position :x) 0) ((eq position :y) 1) ((eq position :z) 2) (t 0))) (loop with string = (elt (coord-strings self) position) with v = (nth position (vars-of self)) for l in (elt (text-links-of self) position) do (setf (viewed-object-of l) (extract-variate (dataset-of self) v)) (if (stringp (text-of l)) (unless (string-equal string (get-text l)) (set-text l string) (update-text-links l)) (draw-view l :erase? t)))) (defmethod update-text-links((self d-view)) (loop for string in (coord-strings self) for labels in (text-links-of self) do (loop for l in labels do (if (stringp (text-of l)) (unless (string-equal string (get-text l)) (set-text l string) (update-text-links l)) (draw-view l :erase? t))))) (defmethod change-variable :after ((self d-view) &key) (update-text-links self)) (defmethod change-case-status :after ((self d-view) cases status &rest args) (declare (ignore cases status args)) (update-text-links self))
3,603
Common Lisp
.l
86
32.848837
92
0.524088
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
595cf96ed016450d776d720d4d5b44ae2238110212f3ff8efb93e1f5f5db8302
33,243
[ -1 ]
33,244
change-var.lsp
rwoldford_Quail/source/views/dview-def/change-var.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; change-var.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) ;;;---------------------------------------------------------------------------------- (defmethod x-variate-links-of ((self 2d-view)) (if (link-vars-p self) (loop with x = (x-variate-of self) for v in (link-bounds-x-of self) when (or (and (typep v '2d-view ) (link-vars-p v) (eq-variate-exprs (x-variate-of v) x)) (and (typep v '1d-view ) (link-vars-p v) (eq-variate-exprs (variate-of v) x))) collect v) (list self))) (defmethod y-variate-links-of ((self 2d-view)) (if (link-vars-p self) (loop with y = (y-variate-of self) for v in (link-bounds-y-of self) when (or (and (typep v '2d-view ) (link-vars-p v) (eq-variate-exprs (y-variate-of v) y)) (and (typep v '1d-view ) (link-vars-p v) (eq-variate-exprs (variate-of v) y))) collect v) (list self))) (defmethod x-variate-links-of ((self 3d-view)) (if (link-vars-p self) (loop with x = (x-variate-of self) for v in (link-bounds-x-of self) when (or (and (typep v '3d-view ) (link-vars-p v) (eq-variate-exprs (x-variate-of v) x)) (and (typep v '2d-view ) (link-vars-p v) (eq-variate-exprs (x-variate-of v) x)) (and (typep v '1d-view ) (link-vars-p v) (eq-variate-exprs (variate-of v) x))) collect v) (list self))) (defmethod y-variate-links-of ((self 3d-view)) (if (link-vars-p self) (loop with y = (y-variate-of self) for v in (link-bounds-y-of self) when (or (and (typep v '3d-view ) (link-vars-p v) (eq-variate-exprs (y-variate-of v) y)) (and (typep v '2d-view ) (link-vars-p v) (eq-variate-exprs (y-variate-of v) y)) (and (typep v '1d-view ) (link-vars-p v) (eq-variate-exprs (variate-of v) y))) collect v) (list self))) (defmethod z-variate-links-of ((self 3d-view)) (if (link-vars-p self) (loop with z = (z-variate-of self) for v in (link-bounds-of self) when (and (typep v '3d-view ) (link-vars-p v) (eq-variate-exprs (z-variate-of v) z)) collect v) (list self))) (defmethod variate-links-of ((self 3d-view)) (if (link-vars-p self) (union (x-variate-links-of self) (union (y-variate-links-of self) (z-variate-links-of self))))) (defmethod variate-links-of ((self d-view)) NIL) (defmethod variate-links-of ((self 2d-view)) (union (x-variate-links-of self) (y-variate-links-of self))) (defmethod variate-links-of ((self 1d-view)) (if (link-vars-p self) (let ((var (variate-of self))) (if (eq (orientation-of self ) :horizontal) (loop for v in (link-bounds-of self) when (or (and (typep v '2d-view ) (link-vars-p v) (eq-variate-exprs (x-variate-of v) var)) (and (typep v '1d-view ) (link-vars-p v) (eq-variate-exprs (variate-of v) var))) collect v) (loop for v in (link-bounds-y-of self) when (or (and (typep v '2d-view ) (link-vars-p v) (eq-variate-exprs (y-variate-of v) var)) (and (typep v '1d-view ) (link-vars-p v) (eq-variate-exprs (variate-of v) var))) collect v))) (list self))) ;;;---------------------------------------------------------------------------------- (defmethod new-variable ((self d-view) &rest args &key ) (apply #'new-sub-views self args) (set-bounding-region self ) ) (defmethod new-variable ((self 2d-view) &rest args &key x y x-function y-function (x-transform :none) (y-transform :none)) (let* ((old-nans? (invalid-cases-p self)) new-nans? ignore-x? ignore-y?) (apply #'new-sub-views self args) (setq new-nans? (member :nan (case-status-of self))) (setq ignore-x? (and (null x) (null x-function) (eq :none x-transform) (null old-nans?) (null new-nans?))) (setq ignore-y? (and (null y) (null y-function) (eq :none y-transform) (null old-nans?) (null new-nans?))) (set-bounding-region self :ignore-x? ignore-x? :ignore-y? ignore-y?) )) (defmethod new-variable :before ((self d-view) &key which var function (transform :none)) (setf (coords-cache-of self) nil) (let ((p (and which (position which (vars-of self) :test #'eq-variate-exprs)))) (when p (if var (setf (elt (vars-of self) p) var)) (if function (setf (elt (funcs-of self) p) function)) (unless (eq :none transform) (setf (elt (transforms-of self) p) transform))))) (defmethod new-variable :before ((self 1d-view) &key var function (transform :none)) (if var (setf (variate-of self) var)) (if function (setf (func-of self) function)) (unless (eq :none transform) (setf (transform-of self) transform)) ) (defmethod new-variable :before ((self 2d-view) &key x x-function (x-transform :none) y y-function (y-transform :none) ) (if x (setf (x-variate-of self) x)) (if y (setf (y-variate-of self) y)) (if x-function (setf (x-func-of self) x-function)) (if y-function (setf (y-func-of self) y-function)) (unless (eq :none x-transform) (setf (x-transform-of self) x-transform)) (unless (eq :none y-transform) (setf (y-transform-of self) y-transform)) ) (defmethod new-variable :before ((self 3d-view) &key x x-function (x-transform :none) y y-function (y-transform :none) z z-function (z-transform :none)) (if x (setf (x-variate-of self) x)) (if y (setf (y-variate-of self) y)) (if z (setf (z-variate-of self) z)) (if x-function (setf (x-func-of self) x-function)) (if y-function (setf (y-func-of self) y-function)) (if z-function (setf (z-func-of self) z-function)) (unless (eq :none x-transform) (setf (x-transform-of self) x-transform)) (unless (eq :none y-transform) (setf (y-transform-of self) y-transform)) (unless (eq :none z-transform) (setf (z-transform-of self) z-transform)) ) (defmethod new-variable :around ((self d-view) &key (draw? nil) ) (if draw? (erase-view self)) (call-next-method) (init-position-subviews self) (if draw? (remap-to-viewports self :erase? nil))) (defmethod new-sub-views ((self d-view) &rest args &key reposition? (relink? t) ) (let* ((old-subs (subviews-of self)) (link-table (if (and old-subs relink?) (link-table-of (car old-subs))))) (loop for subview in old-subs do ;;(break-all-links subview) (loop for vp in (viewports-of self) for vp-sub = (select-viewport subview vp) do (delete-viewport subview vp-sub))) (delete-all-subviews self) (apply #'construct-sub-views self args) (if (and relink? link-table) (loop for sub in (subviews-of self) do (link-view sub :link-table link-table :draw? nil))) (if reposition? (init-position-subviews self)))) ;;=================================================================================================== (defmethod free-axis((self d-view) link) ;; which directions of self are unconstrained by link (cond ((eq link self) nil) ((eq link t) :both) ((typep link 'view) (let ((x? (member self (link-bounds-x-of link))) (y? (member self (link-bounds-y-of link)))) (cond ((and x? y? ) nil) (x? :y) (y? :x) (t :both)))) (t nil))) (defmethod change-variable ((self d-view) &rest args &key (draw? t ) function ) (when (eq function :prompt) (setq function (wb::prompt-user :result-type t :prompt-string "Enter function" :read-type :read)) (if (and (listp function) (symbolp (car function)) (fboundp (car function))) (setq function (eval function) ))) (apply #'new-variable self :draw? draw? :function function args)) (defmethod change-variable :around ((self d-view) &rest args &key (link? t)) (cond ((null link?) (apply #'new-variable self args)) ((= 1 (length (link-bounds-of self))) (apply #'new-variable self args)) ((free-axis self link?) (call-next-method)) (t (apply #'new-variable self :draw? nil args)))) (defmethod change-variable ((self 2d-view) &rest args &key x y x-function y-function (x-transform :none) (y-transform :none) (draw? t) (link? t)) (if (eq x-function :prompt) (setq x-function (wb::prompt-user :result-type t :prompt-string "Enter X function" :read-type :read))) (if (eq y-function :prompt) (setq y-function (wb::prompt-user :result-type t :prompt-string "Enter Y function" :read-type :read))) (let ((new-x? (or x x-function (not (eq :none x-transform)))) (new-y? (or y y-function (not (eq :none y-transform)))) (old-nans? (invalid-cases-p self)) (free-dir (free-axis self link?))) (flet ((pass-to-links () (if new-x? (loop for v in (x-variate-links-of self) do (if (typep v '2d-view ) (change-variable v :x x :x-function x-function :x-transform x-transform :draw? draw? :link? self ) (change-variable v :var x :function x-function :transform x-transform :draw? draw? :link? self )))) (if new-y? (loop for v in (y-variate-links-of self) do (if (typep v '2d-view ) (change-variable v :y y :y-function y-function :y-transform y-transform :draw? draw? :link? self ) (change-variable v :var y :function y-function :transform y-transform :draw? draw? :link? self )))))) (cond ((and (eq free-dir :both) (or (and new-x? new-y?) old-nans? )) (with-constrained-extents self draw? (pass-to-links))) ((or (eq free-dir :both) (eq free-dir (if new-x? :x :y))) (with-constrained-extent self (if new-x? :x :y) draw? (pass-to-links))) ((and old-nans? (or (eq free-dir :both) (not (eq free-dir (if new-x? :x :y))))) (with-constrained-extent self (if new-x? :y :x) draw? (apply #'new-variable self :draw? nil :x-function x-function :y-function y-function args))) (t (apply #'new-variable self :draw? nil :x-function x-function :y-function y-function args) ) )))) (defmethod change-variable :around ((self 2d-view) &rest args &key (draw? t) (link? t) which var function (transform :none)) (let ((find-var (and which (or var function (not (eq :none transform)))))) (cond ((and find-var (eq-variate-exprs which (x-variate-of self))) (call-next-method self :which nil :link? link? :draw? draw? :x var :x-function function :x-transform transform)) ((and find-var (eq-variate-exprs which (y-variate-of self))) (call-next-method self :which nil :link? link? :draw? draw? :y var :y-function function :y-transform transform)) (t (apply #'call-next-method self :link? link? :draw? draw? :which nil args))))) (defmethod change-variable ((self 1d-view) &rest args &key var function (transform :none) (draw? t) (link? t) ) (if (eq function :prompt) (setq function (wb::prompt-user :result-type t :prompt-string "Enter function" :read-type :read))) (let ((axis (axis-of-orientation self)) (free-dir (free-axis self link?))) (flet ((pass-to-links() (loop for v in (variate-links-of self) do (cond ((and (eq axis :x) (typep v '2d-view )) (change-variable v :x var :x-function function :x-transform transform :draw? draw? :link? self )) ((and (eq axis :y) (typep v '2d-view )) (change-variable v :y var :y-function function :y-transform transform :draw? draw? :link? self )) ((typep v '1d-view ) (change-variable v :var var :function function :transform transform :draw? draw? :link? self ) ))))) (if (or (eq free-dir :both) (eq free-dir axis)) (with-constrained-extent self axis draw? (pass-to-links)) (apply #'new-variable self :draw? nil :function function args)))))
15,315
Common Lisp
.l
300
36.24
104
0.48775
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4dc8b5adfafa01269a8b4f8f18cde9ba740474a6303255fa70860d8eebe02401
33,244
[ -1 ]
33,245
d-view-defs.lsp
rwoldford_Quail/source/views/dview-def/d-view-defs.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; d-view-defs.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1988-1991 George Washington University ;;; R.W. Oldford 1988-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(d-view 1d-view 2d-view 3d-view variates-of variate-of transform-of function-of x-variate-of x-transform-of x-function-of y-variate-of y-transform-of y-function-of z-variate-of z-transform-of z-function-of link-bounds-of coords-of plot-coords-of compute-coords summarize case-status-of orientation-of coord-string coord-string-x coord-string-y coord-string-z new-variable change-variable smallest-bounding-region new-case-status change-case-status activate-cases deactivate-cases activate-all-cases ncases set-link-cases-p set-link-vars-p default-dview-function default-dview-transform coord-strings ))) ;;;---------------------------------------------------------------------------------- (defgeneric default-dview-function (variate subject) (:documentation "Returns the default function applied to the~ value of variate")) (defmethod default-dview-function((variate t) (subject t)) #'identity) (defgeneric default-dview-transform (variate data) (:documentation "Returns the default transform applied to the~ value of variate")) (defmethod default-dview-transform((variate t) (data t)) #'identity) #| (defun coerce-data-args-for-dview(&key dataset data cases &allow-other-keys) (setq dataset (or dataset data)) (setq cases (construct-viewed-object-list dataset cases)) (list :data data :cases cases :dataset dataset )) |# (defun compose-initform-fns(fn1 fn2) #'(lambda(&rest args) (let ((ans1 (apply fn2 args))) (append (apply fn1 (append ans1 args)) ans1)))) (defclass d-view (data-menu-item-mixin data-extract-mixin flip-mixin) ((vars ;;:initarg :vars :initform nil :accessor vars-of :documentation "Function or variate names ") (functions :accessor funcs-of ;;:initarg :functions :initform nil :documentation "Functions applied to vars") (transforms ;;:initarg :transforms :initform nil :accessor transforms-of :documentation "transform applied to coords") (coords-cache :initform nil :initarg :coords :accessor coords-cache-of) (case-status :initform nil :initarg :case-status :accessor case-status-of :documentation "allows some cases to be ignored when computing coords, and drawing subs") (bounding-region :initarg :plot-region :initform nil :accessor bounding-region-of :documentation "A region in the local coordinates of view used to define its bounds") (text-links :initform nil :initarg :text-links :accessor text-links-of ) (link-cases? :initform t :initarg :link-cases? :accessor link-cases-p ) (link-vars? :initform t :initarg :link-vars? :accessor link-vars-p ) (value-fn :initarg :value-fn :accessor value-fn-of) (middle-menu :allocation :class :initform nil) ) (:default-initargs :initform-fn #'get-data-inits) (:documentation "Has a viewed-object which is a list of viewed-objects (cases).")) (defclass 1d-view (orientation-mixin d-view) ((right-menu :allocation :class :initform nil) (middle-menu :allocation :class :initform nil)) (:default-initargs :initform-fn #'get-data-inits-1 :function nil :transform nil :orientation-menu? nil)) (defclass 2d-view (d-view) ((middle-menu :allocation :class :initform nil) (right-menu :allocation :class :initform nil)) (:default-initargs :initform-fn #'get-data-inits-2 :x-function nil :x-transform nil :y-function nil :y-transform nil)) (defclass 3d-view (d-view) ((middle-menu :allocation :class :initform nil)) (:default-initargs :initform-fn #'get-data-inits-3 :x-function nil :x-transform nil :y-function nil :y-transform nil :z-function nil :z-transform nil)) ;;;---------------------------------------------------------------------------------- (defgeneric set-link-cases-p (d-view val) (:documentation "Changes link-cases-p, which controls whether~ changes in case status are passed on to other views.")) (defgeneric set-link-vars-p (d-view val) (:documentation "Changes link-vars-p, which controls whether~ changes in variables are passed on to other views.")) (defgeneric ncases(d-view) (:documentation "Returns number of cases(cases)")) (defgeneric coord-string (d-view) (:documentation "Returns a string describing coordinates")) (defgeneric coord-strings (d-view) (:documentation "Returns a string describing coordinates")) (defgeneric coord-string-x (d-view) (:documentation "Returns a string describing x coordinates")) (defgeneric coord-string-y (d-view) (:documentation "Returns a string describing y coordinates")) (defgeneric coord-string-z (d-view) (:documentation "Returns a string describing z coordinates")) ;;;---------------------------------------------------------------------------------- (defgeneric get-cache-coords (d-view ) (:documentation "Computes and caches and returns the list of coords from data")) (defgeneric coords-of (d-view &key cases) (:documentation "Returns list of coords from data")) (defgeneric plot-coords-of (d-view &key cases &allow-other-keys) (:documentation "Returns list of coords used in plot~ not necessarily the same as result of coords-of")) (defgeneric compute-coords (d-view &key cases) (:documentation "Computes and returns list of coords from data" )) ;;;---------------------------------------------------------------------------------- (defgeneric summarize (d-view function &key variate predicate ) (:documentation "Return result of applying function to coords for variate satisfying predicate.~ Variate is ignored for 1d-view")) ;;;---------------------------------------------------------------------------------- (defgeneric new-sub-views (d-view &key &allow-other-keys) (:documentation "Remove current subviews and compute new ones. ~ Use the styles from old views and preserve links.")) (defgeneric remake-sub-views (d-view &key &allow-other-keys) (:documentation "Compute new subviews . ~ Use the styles from old views and preserve links.")) ;;;---------------------------------------------------------------------------------- (defgeneric new-variable (d-view &key &allow-other-keys) (:documentation "Change any of variate, function or transform")) (defgeneric change-variable (d-view &key &allow-other-keys) (:documentation "Changes any of variate, function or transform~ in self and views with linked bounds")) (defgeneric change-case-status (d-view cases status &key &allow-other-keys) (:documentation "Change status of cases in self and links")) (defgeneric new-case-status (d-view cases status &key &allow-other-keys) (:documentation "Change status of cases")) (defgeneric activate-cases (d-view cases &key &allow-other-keys) (:documentation "Change status of cases to activate in self and links")) (defgeneric activate-all-cases (d-view &key &allow-other-keys) (:documentation "Change status of all cases to activate in self and links")) (defgeneric deactivate-cases (d-view cases &key &allow-other-keys) (:documentation "Change status of cases to inactive in self and links ")) ;;;---------------------------------------------------------------------------------- (defgeneric compute-case-status (d-view) (:documentation "Computes the status for cases in d-view ~ Returns and stores a case status list")) (defgeneric select-case-status (d-view case) (:documentation "Returns status of case ")) (defgeneric active-members (d-view list) (:documentation "Returns active members of list.~ List should have same length as viewed object ")) (defgeneric inactive-members (d-view list) (:documentation "Returns inactive members of list.~ List should have same length as viewed object ")) (defgeneric smallest-bounding-region (d-view) (:documentation "Returns the smallest region containing d-view")) (defgeneric functions-of (d-view)) ;(defgeneric coord-strings (d-view)) defined at line 168 ;;;---------------------------------------------------------------------------------- (defmethod initialize-instance :before ((self d-view) &key vars functions transforms) (unless (slot-boundp self 'vars) (setf (slot-value self 'vars) vars)) (unless (slot-boundp self 'functions) (setf (slot-value self 'functions) (or functions (make-list (length (vars-of self)))))) (unless (slot-boundp self 'transforms) (setf (slot-value self 'transforms) (or transforms (make-list (length (vars-of self))))))) (defmethod initialize-instance :before ((self 1d-view) &key var function transform) (if var (setf (slot-value self 'vars) (list var))) (if function (setf (slot-value self 'functions) (list function))) (if transform (setf (slot-value self 'transforms) (list transform)))) (defmethod initialize-instance :before ((self 2d-view) &key x x-function x-transform y y-function y-transform) (if (or x y) (setf (slot-value self 'vars) (list x y))) (if (or x-function y-function) (setf (slot-value self 'functions) (list x-function y-function))) (if (or x-transform y-transform) (setf (slot-value self 'transforms) (list x-transform y-transform)))) (defmethod initialize-instance :before ((self 3d-view) &key x x-function x-transform y y-function y-transform z z-function z-transform) (setf (slot-value self 'vars) (list x y z)) (setf (slot-value self 'functions) (list x-function y-function z-function)) (setf (slot-value self 'transforms) (list x-transform y-transform z-transform))) ;;;---------------------------------------------------------------------------------- (defmethod variate-of ((self 1d-view)) (car (vars-of self))) (defmethod func-of ((self 1d-view)) (let ((f (slot-value self 'functions))) (or (car f) (if f (setf (car f) (default-dview-function (car (vars-of self)) (car (cases-of self)))))))) (defmethod transform-of ((self 1d-view)) (let ((tr (slot-value self 'transforms))) (or (car tr) (if tr (setf (car tr) (default-dview-transform (car (vars-of self)) (dataset-of self))))))) (defmethod (setf variate-of) ( new (self 1d-view)) (if (and (func-of self) (eq (func-of self) (default-dview-function (variate-of self) (car (cases-of self))))) (setf (func-of self) nil)) (if (and (transform-of self) (eq (transform-of self) (default-dview-transform (variate-of self) (dataset-of self)))) (setf (transform-of self) nil)) (setf (car (vars-of self)) new)) (defmethod (setf func-of) ( new (self 1d-view)) (setf (car (funcs-of self)) new)) (defmethod (setf transform-of) ( new (self 1d-view)) (setf (car (transforms-of self)) new)) ;;;---------------------------------------------------------------------------------- (defmethod x-variate-of ((self d-view)) (car (vars-of self))) (defmethod y-variate-of ((self d-view)) (cadr (vars-of self))) (defmethod z-variate-of ((self d-view)) (caddr (vars-of self))) (defmethod funcs-of ((self d-view)) (let ((vo (car (cases-of self))) (fs (slot-value self 'functions))) (loop for f in fs for v in (vars-of self) for i upfrom 0 when (null f) do (setf (nth i fs) (default-dview-function v vo))) fs)) (defmethod transforms-of ((self d-view)) (let ((vo (dataset-of self)) (fs (slot-value self 'transforms))) (loop for f in fs for v in (vars-of self) for i upfrom 0 when (null f) do (setf (nth i fs) (default-dview-transform v vo))) fs)) (defmethod x-func-of ((self d-view)) (let ((f (slot-value self 'functions))) (or (car f) (if f (setf (car f) (default-dview-function (car (vars-of self)) (car (cases-of self)))))))) (defmethod y-func-of ((self d-view)) (let ((f (slot-value self 'functions))) (or (cadr f) (if f (setf (cadr f) (default-dview-function (cadr (vars-of self)) (car (cases-of self)))))))) (defmethod z-func-of ((self d-view)) (let ((f (slot-value self 'functions))) (or (caddr f) (if f (setf (caddr f) (default-dview-function (caddr (vars-of self)) (car (cases-of self)))))))) (defmethod x-transform-of ((self d-view)) (let ((f (slot-value self 'transforms))) (or (car f) (if f (setf (car f) (default-dview-transform (car (vars-of self)) (dataset-of self))))))) (defmethod y-transform-of ((self d-view)) (let ((f (slot-value self 'transforms))) (or (cadr f) (if f (setf (cadr f) (default-dview-transform (cadr (vars-of self)) (dataset-of self))))))) (defmethod z-transform-of ((self d-view)) (let ((f (slot-value self 'transforms))) (or (caddr f) (if f (setf (caddr f) (default-dview-transform (caddr (vars-of self)) (dataset-of self))))))) (defmethod (setf vars-of) ( new (self d-view)) (loop with vos = (dataset-of self) with vo = (car (cases-of self)) for f in (funcs-of self) for tr in (transforms-of self) for v in (vars-of self) for i upfrom 0 when (and f (eq f (default-dview-function v vo))) do (setf (nth i (funcs-of self)) nil) when (and tr (eq tr (default-dview-transform v vos))) do (setf (nth i (transforms-of self)) nil)) (setf (vars-of self) new)) (defmethod (setf x-variate-of) ( new (self d-view)) (if (and (x-func-of self) (eq (x-func-of self) (default-dview-function (x-variate-of self) (car (cases-of self))))) (setf (x-func-of self) nil)) (if (and (x-transform-of self) (eq (x-transform-of self) (default-dview-transform (x-variate-of self) (dataset-of self)))) (setf (x-transform-of self) nil)) (setf (car (vars-of self)) new)) (defmethod (setf y-variate-of) ( new (self d-view)) (if (and (y-func-of self) (eq (y-func-of self) (default-dview-function (y-variate-of self) (car (cases-of self))))) (setf (y-func-of self) nil)) (if (and (y-transform-of self) (eq (y-transform-of self) (default-dview-transform (y-variate-of self) (dataset-of self)))) (setf (y-transform-of self) nil)) (setf (cadr (vars-of self)) new)) (defmethod (setf z-variate-of) ( new (self d-view)) (if (and (z-func-of self) (eq (z-func-of self) (default-dview-function (z-variate-of self) (car (cases-of self))))) (setf (z-func-of self) nil)) (if (and (z-transform-of self) (eq (z-transform-of self) (default-dview-transform (z-variate-of self) (dataset-of self)))) (setf (z-transform-of self) nil)) (setf (caddr (vars-of self)) new)) (defmethod (setf x-func-of) ( new (self d-view)) (setf (car (funcs-of self)) new)) (defmethod (setf y-func-of) ( new (self d-view)) (setf (cadr (funcs-of self)) new) ) (defmethod (setf z-func-of) (new (self d-view)) (setf (caddr (funcs-of self)) new)) (defmethod (setf x-transform-of) ( new (self d-view)) (setf (car (transforms-of self)) new)) (defmethod (setf y-transform-of) ( new (self d-view)) (setf (cadr (transforms-of self)) new)) (defmethod (setf z-transform-of) (new (self d-view)) (setf (caddr (transforms-of self)) new)) (defmethod set-link-cases-p ((self d-view) val) (if (eq val :toggle) (setf (link-cases-p self) (not (link-cases-p self))) (setf (link-cases-p self) val))) (defmethod set-link-vars-p ((self d-view) val) (if (eq val :toggle) (setf (link-vars-p self) (not (link-vars-p self))) (setf (link-vars-p self) val)))
18,479
Common Lisp
.l
409
35.958435
99
0.56519
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
2087ebe41b620b2132694a8c961f7e9a14372d266ee10b178d57d391ff3f003a
33,245
[ -1 ]
33,246
close-button.lsp
rwoldford_Quail/source/views/selection/close-button.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; close-button.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1995 Maynooth ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (eval-when (:compile-toplevel :load-toplevel :execute) (export '( fixed-size-rectangle close-button))) (in-package :views) (defclass close-button(fixed-size-rectangle control-button) () (:default-initargs :text "Close" :font wb:*normal-graphics-font* :bg-color wb:*white-color* :color wb:*black-color* :width 60 :height 20 )) (defmethod left-button-fn ((self close-button) &key viewport ) (control-start self) (wb::close-canvas (window-of viewport )) ) (defmethod reshape-viewport :after ((self fixed-size-rectangle) viewport &rest ignore) (declare (ignore ignore viewport)) (fix-viewports self)) (defmethod add-viewport :after ((self fixed-size-rectangle) viewport pvp &key) (declare (ignore pvp)) (fix-viewports self :viewport viewport)) (defmethod fix-viewports ((self fixed-size-rectangle) &key viewport ) (let ((w (rectangle-width-of self)) (h (rectangle-height-of self))) (loop for vp in (if viewport (list viewport) (viewports-of self) ) do (set-viewport-width-height vp w h))))
1,798
Common Lisp
.l
46
33.695652
105
0.528522
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f0a77966bc63ce3b899090b28cc7ee5e639a886fc4ee01a2f99e952e8f75e2ce
33,246
[ -1 ]
33,247
selection.lsp
rwoldford_Quail/source/views/selection/selection.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; selection-list.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1995 Maynooth ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (eval-when (:compile-toplevel :load-toplevel :execute) (export '( display-list-selection-mixin single-selection-list multi-selection-list select-from-list))) (in-package :views) (defclass display-list-selection-mixin () ((display-selection :initform nil :initarg :display-selection :accessor display-selection-of))) (defclass single-selection-list (display-list-selection-mixin display-list) ()) (defclass multi-selection-list (display-list-selection-mixin display-list) ()) (defgeneric display-selection-function (display-list-selection-mixin) (:documentation "Returns a function which is invoked with a left click ~ on subview of the display list")) (defgeneric selected-data-of (display-list-selection-mixin) (:documentation "Returns a the items which have been selected from ~ the display list.")) (defmethod display-selection-function ((self display-list-selection-mixin)) nil) (defmethod selected-data-of ((self display-list-selection-mixin)) nil) (defmethod construct-sub-views :after ((self display-list-selection-mixin) &rest args ) (declare (ignore args)) (let* ((f1 (display-selection-function self))) (when f1 (loop for s in (subviews-of self) do (setf (left-fn-of s) f1))))) (defmethod selected-data-of ((self single-selection-list)) (let ((d (display-selection-of self))) (if d (viewed-object-of d)))) (defmethod display-selection-function ((self single-selection-list)) #'(lambda(sub) (let ((old (display-selection-of self))) (when old (deselect-menu-label old) (if (eql sub old) (setq sub nil))) (if sub (select-menu-label sub)) (setf (display-selection-of self) sub) ))) (defmethod selected-data-of ((self multi-selection-list)) (let ((d (display-selection-of self))) (mapcar #'viewed-object-of d))) (defmethod display-selection-function ((self multi-selection-list)) #'(lambda(sub) (let ((ans (display-selection-of self))) (if (member sub ans) (progn (deselect-menu-label sub) (setf (display-selection-of self) (delete sub ans))) (progn (select-menu-label sub) (setf (display-selection-of self) (append ans (list sub)))) )))) ;;---------------------------------------------------------------------------------------- (defun select-from-list (list &key prompt-text (item-function NIL) (selection-type :single) (selection-item-type 'marked-menu-label) selection-display-type) "This pops up a window so the user can choose from the list. ~ If selection-type is :single (the default) only a single ~ selection is allowed, any other value of selection-type permits ~ multiple selections. ~ Further control of selection behavior is possible by giving a suitable ~ class name for :selection-display-type, and of menu label appearance ~ through the :selection-item-type keyword. " (if (null prompt-text) (setq prompt-text (if (eq selection-type :single) "Choose One" "Choose"))) (if (null selection-display-type) (setq selection-display-type (if (eq selection-type :single) 'single-selection-list 'multi-selection-list))) (let* ((okw 40) (okh 20) (indent 10) (scroll 15) (menu-list (display-list :display-type selection-display-type :data list :labels item-function :display-list-border 2 :item-type selection-item-type :draw? nil)) (ok (view :type 'close-button :text "OK" :rectangle-width okw :rectangle-height okh)) (dw (draw-region-width menu-list)) (dh (draw-region-height menu-list)) (bigr-wid (max 150 (+ (* 2 indent) dw))) (bigr-hgt (max 150 (+ (* 2 indent) dh (* 2 okh)))) (l (max scroll (- (truncate (wb:screen-width) 2) (truncate bigr-wid 2)))) (tp (- (wb:screen-height) 100)) (bigr (make-region l (+ l bigr-wid) (max scroll (- tp bigr-hgt)) tp)) (select-view (view-layout :box-views? t :subviews (list menu-list ok) :bounding-region bigr :positions (list (make-region (+ indent l) (- (right-of bigr) indent) (- (top-of bigr) indent dh) (- (top-of bigr) indent)) (make-region (+ indent l) (- (right-of bigr) indent) (+ (bottom-of bigr) indent) (+ (bottom-of bigr) indent okh))))) (w (make-view-window :background-color wb:*light-grey-color* :pen-color wb:*black-color* :title prompt-text :left (- (left-of bigr) scroll) :bottom (- (bottom-of bigr) scroll) :right (right-of bigr) :top (top-of bigr))) ) (draw-view select-view :viewport (make-viewport w)) (loop ;;with start-time = (get-universal-time) ;; with wait-time = 20 until (not (wb:canvas-visible-p w)) do (ccl::event-dispatch) ) (selected-data-of menu-list) ))
6,660
Common Lisp
.l
152
31.611842
118
0.516522
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
8ec220b6f433c7405a9980ef21d238944705218108e6bb40a0dd775e8e678b90
33,247
[ -1 ]
33,248
var-selection.lsp
rwoldford_Quail/source/views/selection/var-selection.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; var-selection.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1995 Maynooth ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(xy-menu-label xyz-menu-label single-xy-selection-list single-xyz-selection-list multi-xy-selection-list select-xyz-variables select-xy-variables))) (defclass xy-menu-label(marked-menu-label) ((left-menu :allocation :class :initform nil))) (defclass xyz-menu-label(marked-menu-label) ((left-menu :allocation :class :initform nil)) ) (defclass single-xy-selection-list (display-list-selection-mixin variate-display-list) () (:default-initargs :display-selection (list nil nil))) (defclass single-xyz-selection-list (single-xy-selection-list) () (:default-initargs :display-selection (list nil nil nil))) (defclass multi-xy-selection-list (display-list-selection-mixin variate-display-list) () (:default-initargs :display-selection (list nil nil))) ;;;---------------------------------------------------------------------------------- (defmethod get-menu-items ((self xy-menu-label) (slot-name (eql 'left-menu))) `(("X" "X") ("Y" "Y") )) (defmethod get-menu-items ((self xyz-menu-label) (slot-name (eql 'left-menu))) `(("X" "X") ("Y" "Y") ("Z" "Z") )) (defmethod default-left-fn ((self xy-menu-label) &key viewport ) (invert-view self :viewport viewport) (let ((mark (wb:menu (menu-of self 'left-menu)))) (invert-view self :viewport viewport) (if mark (select-menu-label self :mark mark)) )) (defmethod default-left-fn ((self xyz-menu-label) &key viewport ) (declare (ignore viewport)) (let ((mark (wb:menu (menu-of self 'left-menu)))) (if mark (select-menu-label self :mark mark)))) ;;;---------------------------------------------------------------------------------- (defmethod selected-data-of ((self single-xy-selection-list)) (let ((d (display-selection-of self))) (mapcar #'(lambda(x) (if x (viewed-object-of x))) d))) (defmethod display-selection-function ((self single-xy-selection-list)) #'(lambda(sub) (default-left-fn sub :viewport (car (viewports-of sub))) (let ((mark (mark-of sub))) (if (equal mark "X") (setf (first (display-selection-of self)) sub) (setf (second (display-selection-of self)) sub)) (loop for s in (subviews-of self) when (and (not (eql s sub)) (equal (mark-of s) mark)) do (deselect-menu-label s))) )) (defmethod display-selection-function ((self single-xyz-selection-list)) #'(lambda(sub) (default-left-fn sub :viewport (car (viewports-of sub))) (let ((mark (mark-of sub))) (if (equal mark "X") (setf (first (display-selection-of self)) sub) (if (equal mark "Y") (setf (second (display-selection-of self)) sub) (setf (third (display-selection-of self)) sub))) (loop for s in (subviews-of self) when (and (not (eql s sub)) (equal (mark-of s) mark)) do (deselect-menu-label s))))) (defmethod selected-data-of ((self multi-xy-selection-list)) (let ((d (display-selection-of self))) (list (mapcar #'viewed-object-of (first d)) (mapcar #'viewed-object-of (second d))))) (defmethod display-selection-function ((self multi-xy-selection-list)) #'(lambda(sub) (let ((ansx (first (display-selection-of self))) (ansy (second (display-selection-of self)))) (let ((old-mark (mark-of sub)) mark) (default-left-fn sub :viewport (car (viewports-of sub))) (if (equal (setq mark (mark-of sub)) old-mark) (progn (deselect-menu-label sub) (if (equal mark "X") (setf (first (display-selection-of self)) (delete sub ansx)) (setf (second (display-selection-of self)) (delete sub ansy)))) (if (equal mark "X") (setf (first (display-selection-of self)) (append ansx (list sub))) (setf (second (display-selection-of self)) (append ansy (list sub))))))))) (defun select-xy-variables (data &key prompt-text (selection-type :single) (selection-item-type 'xy-menu-label) selection-display-type) "This pops up a window so the user can choose X and Y variables ~ from data. ~ If selection-type is :single (the default) only one X and one Y variable ~ may be selected. Otherwise multiple Xs and Ys are allowed. ~ Further control of selection behavior is possible by giving a suitable ~ class name for :selection-display-type, and of menu label appearance ~ through the :selection-item-type keyword. " (if (null prompt-text) (setq prompt-text (if (eq selection-type :single) "Choose X and Y" "Choose Xs and Ys"))) (if (null selection-display-type) (setq selection-display-type (if (eq selection-type :single) 'single-xy-selection-list 'multi-xy-selection-list))) (select-from-list data :prompt-text prompt-text :selection-type selection-type :selection-item-type selection-item-type :selection-display-type selection-display-type)) (defun select-xyz-variables (data &key prompt-text (selection-type :single) (selection-item-type 'xyz-menu-label) (selection-display-type 'single-xyz-selection-list)) "This pops up a window so the user can choose X, Y and Z variables ~ from data. ~ Further control of selection behavior is possible by giving a suitable ~ class name for :selection-display-type, and of menu label appearance ~ through the :selection-item-type keyword. " (if (null prompt-text) (setq prompt-text (if (eq selection-type :single) "Choose X, Y, Z" "Choose X, Y, Zs"))) (select-from-list data :prompt-text prompt-text :selection-type selection-type :selection-item-type selection-item-type :selection-display-type selection-display-type))
7,243
Common Lisp
.l
155
36.741935
119
0.549386
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fddc843006694b0e8f77ce08c7a7fc63e09d42079782581423ae5f7afa44049d
33,248
[ -1 ]
33,249
menu-label.lsp
rwoldford_Quail/source/views/selection/menu-label.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; menu-label.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1995 Maynooth ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (eval-when (:compile-toplevel :load-toplevel :execute) (export '( menu-label marked-menu-label select-menu-label deselect-menu-label))) (in-package :views) (defclass menu-label(bg-color-mixin label) ((style-keys :initform '(:font :color :bg-color :highlight-color) :allocation :class) ) (:default-initargs :bg-color wb:*white-color* :color wb:*black-color* :highlight-color *default-highlight-color*) ) (defclass marked-menu-label( menu-label) ((mark :initarg :mark :accessor mark-of :initform "" :documentation "marks the label"))) (defgeneric select-menu-label (menu-label &key &allow-other-keys)) (defgeneric deselect-menu-label (menu-label)) (defmethod select-menu-label ((self menu-label) &key) (draw-view self :color (draw-style self :highlight-color) :erase? t)) (defmethod deselect-menu-label ((self menu-label) ) (draw-view self :erase? t)) (defmethod get-text :around ((self marked-menu-label)) (if (mark-of self) (format nil "~A ~A" (mark-of self) (call-next-method)) (call-next-method))) (defmethod default-mark ((self marked-menu-label)) #\dot) (defmethod select-menu-label ((self marked-menu-label) &key (mark (default-mark self))) (unless (equal mark (mark-of self)) (erase-view self) (setf (mark-of self) mark) (draw-view self :color (draw-style self :highlight-color))) ) (defmethod deselect-menu-label ((self marked-menu-label) ) (erase-view self) (setf (mark-of self) "") (draw-view self) ) (defmethod set-label-mark ((self marked-menu-label) &key (mark (default-mark self)) (draw? t)) (if draw? (erase-view self)) (setf (mark-of self) mark) (if draw? (draw-view self)))
2,465
Common Lisp
.l
63
33.936508
138
0.561411
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
886703eb1a6242928f5c5700472d116c50d9670d7820fe35c65b9cdfcc90a146
33,249
[ -1 ]
33,250
test.lsp
rwoldford_Quail/source/views/selection/test.lsp
(defun choose-variable (&optional dataset (n 1) msg menu-items) "Choose n variables from dataset" (setq msg (or msg (if (= n 1) "Choose a variable" (format nil "Choose ~A variables" n)))) ( setq menu-items (or menu-items (if dataset (variable-menu-items dataset)))) (if menu-items (if (= n 1) (second (select-from-list menu-items :prompt-text msg :item-function #'first)) (loop for result = (select-from-list menu-items :prompt-text msg :item-function #'first :selection-type :multi) when result append result into result-list and do (setq msg (format nil "Choose ~A more" (- n (length result-list)))) until (>= (length result-list) n ) finally (return (subseq (mapcar #'second result-list) 0 n)))) (loop for i from 1 to n collect (wb::prompt-user :type t :read-type :eval :prompt-string msg)))) (choose-variable q-user::apple) (select-xy-variables q-user::apple) (trace selected-data-of)
1,185
Common Lisp
.l
22
39.590909
83
0.548443
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
91af6cc4fd7ca45ac6150137a16516e1934887f576d018ffe598bc9b630bb02d
33,250
[ -1 ]
33,251
view-layout.lsp
rwoldford_Quail/source/views/layout/view-layout.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; view-layout.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;------------------------------------------------ (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(view-layout default-layout-sub-views batch-sub-views view-layout-position-subviews 1d-sub-views))) (defgeneric default-layout-sub-views (view &key &allow-other-keys)) (defclass view-layout(data-menu-item-mixin boxed-subview-mixin compound-view ) ((positions :initform nil :initarg :positions :accessor positions-of) (middle-menu :allocation :class :initform nil) (link-bounds-x? :initform nil :initarg :link-bounds-x? :accessor link-bounds-x-p) (link-bounds-y? :initform nil :initarg :link-bounds-y? :accessor link-bounds-y-p) (layout-views :initform nil :initarg layout-views :accessor layout-views-of) (subview-position-fn :initform #'view-layout-position-subviews :initarg :subview-position-fn :accessor subview-position-fn-of)) (:default-initargs :link-bounds-x? nil :link-bounds-y? nil :batches nil :subview-constructor nil :box-views? nil :nsubviews :prompt ) (:documentation "A compound view for laying out subviews. ~ The user supplies views, or information to ~ construct views, and a position for each view. ~ The position may be a function which when applied to ~ each view yields its position.")) (defmethod construct-sub-views ((self view-layout) &rest keyword-pairs &key subview-constructor batches) (setq subview-constructor (or subview-constructor (if batches #'batch-sub-views #'default-layout-sub-views))) (apply subview-constructor self keyword-pairs)) (defmethod init-position-subviews ((self view-layout) &rest keyword-pairs &key ) (let ((fn (subview-position-fn-of self))) (if (and fn (null (subview-locns-of self))) (apply fn self :allow-other-keys t keyword-pairs)))) (defmethod var-info ((self view) var-args) (setq var-args (or var-args (let ((d (cond ((or (typep self 'd-view) (typep self 'bar-chart) (typep self 'pairs-layout) (typep self '1d-layout)) self) ((typep self 'plot) (interior-view-of self)) ((typep self 'plot) (interior-view-of self)) (t nil)))) (if (null d) (setq d (car (descendant-views-of-type self 'd-view )))) (cond ((null d) nil) ((typep d '2d-view) (list :x (x-variate-of d) :y (y-variate-of d) :x-function (x-func-of d) :y-function (y-func-of d) :x-transform (x-transform-of d) :y-transform (y-transform-of d))) ((typep d '1d-view) (list :var (variate-of d) :function (func-of d) :transform (transform-of d))) ((typep d '3d-view) (list :x (x-variate-of d) :y (y-variate-of d) :z (z-variate-of d) :x-function (x-func-of d) :y-function (y-func-of d) :z-function (z-func-of d) :x-transform (x-transform-of d) :y-transform (y-transform-of d) :z-transform (z-transform-of d))) ((or (typep d 'pairs-layout) (typep d '1d-layout)) (list :vars (vars-of d) :functions (funcs-of d) :transforms (transforms-of d))) ((typep d 'd-view) (list :vars (vars-of d) :functions (funcs-of d) :transforms (transforms-of d))) ((typep d 'bar-chart) (list :batches (if (functionp (batches-of d)) (batches-of d)) :by (by-vars-of d))) (t nil))))) (unless (getf var-args :case-view) (let* ((c (cond ((typep self 'one-per-case-mixin) self) ((and (typep self 'plot) (typep (interior-view-of self) 'one-per-case-mixin)) (interior-view-of self)) (t nil))) cv) (if (null c) (setq c (car (descendant-views-of-type self 'one-per-case-mixin)))) (setq cv (if c (car (sub-views-of c)))) (if cv (setq var-args (append var-args (list :case-view (class-name (class-of cv)))))))) var-args) (defun repeat-list(list n) (if (and list (numberp n)) (loop while (< (length list) n) do (setq list (append list list)) finally (return (subseq list 0 n))) list)) (defmethod default-layout-sub-views ((self view-layout) &key nsubviews subviews subview-type default-subview-type (common-vars? nil) (common-case-views? nil) ordered-case-views? case-views-from (subview-superclass '(or simple-view compound-view))) (let* ((vo (viewed-object-of self)) (case-args (list :case-views-from case-views-from :ordered-case-views? ordered-case-views?)) smooth-info brush-info (sub-list (nconc case-args (list :data vo))) var-args) (setq case-views-from nil) (labels ((local-make-view(arg &optional (type default-subview-type)) (let ((v (if (view-p arg) arg (apply #'view (append (if (listp type) type (list :type type)) (subview-arg-list arg default-subview-type) sub-list var-args))))) (if common-vars? (setq var-args (var-info v var-args))) (when (and (null smooth-info) (typep v 'smooth-mixin)) (setq smooth-info (list :smooth-par (smooth-par-of v))) (setq var-args (nconc smooth-info var-args))) (when (and (null brush-info) (typep v 'brushable-view-mixin)) (setq brush-info (list :brush (brush-of v))) (setq var-args (nconc brush-info var-args))) (when (and common-case-views? (null case-views-from) ) (if (typep v 'one-per-case-mixin) (progn (setf (getf case-args :case-views-from) v) (setf (getf case-args :ordered-case-views?) t)) (if (and (typep v 'plot) (typep (interior-view-of v) 'one-per-case-mixin)) (progn (setf (getf case-args :case-views-from) v) (setf (getf case-args :ordered-case-views?) t))))) v)) (local-make-views (arg types) (mapcar #'(lambda(type) (local-make-view arg type)) types))) (if (and (null nsubviews) (numberp subviews)) (rotatef nsubviews subviews)) (when (and (eq nsubviews :prompt) (numberp subviews)) (setf nsubviews subviews) (setf subviews NIL)) (setq subviews (cond ((and subviews (listp subviews)) (repeat-list subviews nsubviews)) ((and (numberp nsubviews) (> nsubviews 0) (null subview-type) (null default-subview-type) (typep self 'grid-layout)) (let ((vt (choose-view-from-menu :prompt-string "Select layout view" :superclass subview-superclass))) (make-list nsubviews :initial-element vt))) ((and (numberp nsubviews) (> nsubviews 0) (null subview-type) (null default-subview-type)) (repeat-list (choose-views-from-menu :prompt-string "Select layout views" :nmax nsubviews :superclass subview-superclass) nsubviews)) ((numberp nsubviews) (make-list nsubviews)) ((and (null subviews) (eql nsubviews :prompt) (null subview-type) (null default-subview-type)) (choose-views-from-menu :superclass subview-superclass :prompt-string "Select layout views" )) (t nil))) (let ((layout-status (loop for s in subviews collect (cond ((legal-view-construct-p s) :legal) ((and (listp s) (every #'legal-view-construct-p s)) :layer) (t (quail-error "Illegal subview argument ~A" s)))))) (if subview-type (loop with subview-types = (if (legal-view-construct-p subview-type) (list subview-type) subview-type) for s in subviews for status in layout-status for new = (ecase status (:legal (local-make-views s subview-types)) (:layer (loop for si in s append (local-make-views si subview-types)))) collect new into lviews append new into sviews finally (setf (subviews-of self) sviews) (setf (layout-views-of self) lviews)) (loop for s in subviews for status in layout-status for new = (ecase status (:legal (list (local-make-view s))) (:layer (mapcar #'local-make-view s))) collect new into lviews append new into sviews finally (setf (subviews-of self) sviews) (setf (layout-views-of self) lviews)))))) ) (defmethod view-layout-position-subviews ((self view-layout) &key positions bounding-region) ;(flet ((plistp(arg) ; 04SEP2023 and next 4 lines ; (and (listp arg) ; (evenp (length arg)) ; (loop for key in arg by #'cddr ; always (keywordp key))))) (constrain-bounds self) (let ((subs (layout-views-of self)) sub-regions) (when subs (setf (positions-of self) (loop for i from 0 below (length subs) collect (if (and positions (listp positions)) (elt positions i) positions))) (loop for layer-list in subs for pos in (positions-of self) do (loop with s = (car layer-list) repeat (length layer-list) do (push (cond ((region-p pos) pos) ((and pos (listp pos)) (apply #'make-region pos)) ((functionp pos) (funcall pos s) ) ((and pos (symbolp pos)) (funcall (get-function pos) s)) (t (bounding-region-of s))) sub-regions))) (setf (sub-view-locns-of self) (nreverse sub-regions)) (if (and (positions-of self) (null bounding-region)) (set-bounding-region self :region (compute-containing-bounding-region self))) )) ;) ; 04SEP2023 ) (defmethod use-x-axis-p ((self view-layout)) t) (defmethod use-y-axis-p ((self view-layout)) t) (defmethod compute-containing-bounding-region ((self view-layout) ) (or (loop for svl in (sub-view-locns-of self) minimize (left-of svl) into left maximize (right-of svl) into right minimize (bottom-of svl) into bottom maximize (top-of svl) into top finally (return (make-region left right bottom top))) (make-region))) (defmethod constrain-bounds ((self view-layout) &key draw? (link-bounds-x? :ignore) (link-bounds-y? :ignore)) (unless (eq link-bounds-x? :ignore) (setf (link-bounds-x-p self) link-bounds-x?)) (unless (eq link-bounds-y? :ignore) (setf (link-bounds-y-p self) link-bounds-y?)) (if (link-bounds-x-p self) (let* ((x-views (loop for v in (subviews-of self) when (linkable-bounds-x-p v) collect v)) (d-views (loop for v in x-views when (and (typep v 'd-view) (use-x-axis-p v)) collect v))) (link-view-bounds x-views :x) (set-view-extents x-views :x :recompute? nil :region (if d-views (maximize-x-extents d-views))))) (if (link-bounds-y-p self) (let* ((y-views (loop for v in (subviews-of self) when (linkable-bounds-y-p v) collect v)) (d-views (loop for v in y-views when (and (typep v 'd-view) (use-y-axis-p v)) collect v))) (link-view-bounds y-views :y) (set-view-extents y-views :y :recompute? nil :region (if d-views (maximize-y-extents d-views))))) (when (or (link-bounds-x-p self) (link-bounds-y-p self)) (remap-to-viewports self :erase? draw? :draw? draw?))) (defmethod delete-subview :before ((self view-layout) view) (setf (layout-views-of self) (loop for views in (layout-views-of self) for del = (delete view views) when del collect del))) (defmethod add-to-named-slot ((self view-layout) old new) (setf (layout-views-of self) (loop for views in (layout-views-of self) collect (if (member old views) (append views (list new)) views)))) (defmethod add-subview :after ((self view-layout) subview new-region) (declare (ignore new-region)) (when (legal-subview-p self subview) (push (list subview) (layout-views-of self)))) (defmethod layer-subview :after ((self view-layout) view on &rest arg ) (declare (ignore arg)) (add-to-named-slot self on view)) (defmethod dview-subview ((self view-layout)) (or (car (subviews-of-type self 'd-view)) (car (descendant-views-of-type self 'd-view)))) (defmethod menu-properties ((self view-layout) (slot-name (eql 'middle-menu))) (let ((dv (dview-subview self))) (if (typep dv 'data-menu-item-mixin) (acons :dim (ndims dv) (copy-tree (menu-properties dv 'middle-menu )))))) (defmethod get-menu-items ((self view-layout) (slot-name (eql 'middle-menu))) (let ((v-items (var-menu-items self)) (c-items (case-menu-items self)) items) (setq items (append (if v-items `(("Variables" nil "" :sub-items ,v-items))) (if c-items `(("Cases" nil "" :sub-items ,c-items))))) (setq items (append items `(("Point symbols" nil "" :sub-items ,(ps-subview-menu-items))))) (cons '("-" nil) items))) (defmethod var-menu-items ((self view-layout) &key target) (let ((dv (dview-subview self))) (if (typep dv 'data-menu-item-mixin) (var-menu-items dv :method 'change-variable :target target)))) (defmethod case-menu-items ((self view-layout) &key target) (let ((dv (dview-subview self))) (if (typep dv 'data-menu-item-mixin) (case-menu-items dv :target target)))) (defmethod change-variable ((self view-layout) &rest args &key which (draw? t)) ;; changes variable its function or transform and redraws plot (let (from-view) (if (null which) (setq from-view (car (intersection *selected-views* (subviews-of-type self 'd-view))))) (if (typep from-view 'd-view) (setq which (car (vars-of from-view)))) (if (null which) (quail-error "Please select variate to change")) (if (null from-view) (setq from-view (loop for v in (subviews-of-type self 'd-view) thereis (and (eq-variate-exprs (car (vars-of v)) which) v)))) (when (and from-view (has-variates-p from-view)) (apply #'change-variable from-view :draw? draw? :which which args))))
18,191
Common Lisp
.l
361
34.047091
114
0.504079
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
8b75d734a36580d7f4737c1632910a841b6f004e835e785779aa8ce3863df7e6
33,251
[ -1 ]
33,252
pairs-layout.lsp
rwoldford_Quail/source/views/layout/pairs-layout.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; pairs-layout.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(pairs-layout add-diagonal-views pairs-sub-views init-label-texts))) (defclass pairs-layout (grid-layout) ((middle-menu :allocation :class :initform nil)) (:default-initargs :box-views? t :pairs-view '2d-point-cloud :diag-view 'label :gap-x 0.05 :gap-y 0.05 :link-bounds-x? :by-col :link-bounds-y? :by-row :initform-fn #'get-data-inits :min-nvars 2 :subview-constructor #'pairs-sub-views )) (defgeneric add-diagonal-views (pairs-layout &rest arg &key type &allow-other-keys) (:documentation "Adds views of given type on diagonal")) (defgeneric pairs-sub-views (pairs-layout &key &allow-other-keys)) (defmethod construct-sub-views :after ((self pairs-layout) &key) ;;Catherine, here's the hack that ensures that the layout-format is correct. (setf (layout-format-of self) (list (nrows-of self) (ncols-of self))) (init-label-texts self)) (defmethod init-label-texts ((self pairs-layout)) (loop with n = (length (layout-views-of self)) with nrows = (nrows-of self) with jx with jy with pair-y with pair-x for i upfrom 0 for views in (layout-views-of self) for label = (loop for v in views thereis (and (typep v 'label) v)) when (and label (string-equal "" (get-text label)) )do (setq jy (if (= i (- n 1)) (- i 1) (+ i 1))) (setq jx (if (= i (- n 1)) (- i nrows) (+ i nrows))) (setq pair-y (if (> jy 0) (nth 0 (nth jy (layout-views-of self))))) (setq pair-x (if (> jx 0) (nth 0 (nth jx (layout-views-of self))))) (setf (text-of label) (if pair-y (progn (text-link pair-y label :y) (or (coord-string-y pair-y) "VAR")) "VAR")) (if pair-x (text-link pair-x label :x)))) (defmethod prompt-for-pairs-view((self pairs-layout)) (choose-views-from-menu :prompt-string "Select pair view(s)" :superclass '2d-view)) (defmethod pairs-sub-views ((self pairs-layout) ;; &rest keyword-pairs &key (cases #'list-cases) (value-fn #'value-of) labels coords vars functions transforms ordered-case-views? (common-case-views? t) case-views-from pairs-view diag-view) (unless common-case-views? (setq case-views-from nil)) (let* ((n (length vars)) (fns (or functions (make-list n))) (trans (or transforms (make-list n ))) (pair-args (loop for y in vars for fy in fns for afy in trans append (loop for x in vars for fx in fns for afx in trans unless (eql x y) collect (list :x x :x-function fx :x-transform afx :y y :y-function fy :y-transform afy)))) (diag-args (loop for v in vars for f in fns for af in trans for l in (or (and (listp labels) labels) (make-list n :initial-element labels)) collect (list :var v :function f :transform af :text (or l "")))) (add-args (list :data (viewed-object-of self) :cases cases :value-fn value-fn :ordered-case-views? ordered-case-views? :case-views-from case-views-from )) pair-layout diag-layout mem) (cond ((eql pairs-view :prompt) (setf pairs-view (prompt-for-pairs-view self))) ((or (null pairs-view) (eql pairs-view :default)) (setf pairs-view '2d-point-cloud)) ((and (listp pairs-view) (setq mem (member :default pairs-view))) (setf (car mem) '2d-point-cloud))) (if (legal-view-construct-p pairs-view) (loop with subview-arg = (append (subview-arg-list pairs-view '2d-point-cloud) add-args) with c-coords with first-pc = nil for arg in pair-args for i upfrom 0 for y = (truncate i (- n 1)) for x = (mod (+ i 1 (truncate i n)) n) for new-coords = (if coords (mapcar #'list (elt coords x) (elt coords y)) (if (and c-coords (>= i (- n 1))) (mapcar #'list (elt c-coords x) (elt c-coords y)))) for new-view = (apply #'view :coords new-coords (append arg subview-arg)) collect (list new-view) into lviews do (when (and common-case-views? (null first-pc) (typep new-view 'one-per-case-mixin)) (setq first-pc new-view) (setf (getf add-args :case-views-from) first-pc) (setf (getf add-args :ordered-case-views?) t)) (when (and (null coords) (typep new-view 'd-view)) (if (= i 0) (setq c-coords (list (y-coords-of new-view) (x-coords-of new-view))) (if (< i ( - n 1)) (setq c-coords (append c-coords (list (x-coords-of new-view))))))) finally (setf pair-layout lviews)) (loop with c-coords with new-view for arg in pair-args for i upfrom 0 for y = (truncate i (- n 1)) for x = (mod (+ i 1 (truncate i n)) n) for new-coords = (if coords (mapcar #'list (elt coords x) (elt coords y)) (if (and c-coords (>= i (- n 1))) (mapcar #'list (elt c-coords x) (elt c-coords y)))) for new-views = (loop for pairs-v in pairs-view for subview-arg = (append (subview-arg-list pairs-v '2d-point-cloud) add-args) for the-view = (apply #'view :coords new-coords (append arg subview-arg)) collect the-view when (and common-case-views? (null case-views-from) (typep the-view '2d-point-cloud)) do (setf case-views-from new-view) (setf (getf add-args :ordered-case-views?) t) ;; added 25-3-97 (setf (getf add-args :case-views-from) new-view)) collect new-views into lviews do (setq new-view (loop for v in new-views thereis (and (typep v '2d-view) v))) (when (and (null coords) (typep new-view 'd-view)) (if (= i 0) (setq c-coords (if (and new-view (typep new-view 'd-view)) (list (y-coords-of new-view) (x-coords-of new-view)) (list nil nil))) (if (< i ( - n 1)) (setq c-coords (append c-coords (if (and new-view (typep new-view 'd-view)) (list (x-coords-of new-view)) (list nil))))))) finally (setf pair-layout lviews))) (if (legal-view-construct-p diag-view) (loop with subview-arg = (append (subview-arg-list diag-view 'label) add-args) for arg in diag-args for new-view = (apply #'view (append arg subview-arg)) collect (list new-view) into lviews finally (setf diag-layout lviews)) (loop for arg in diag-args for new-views = (loop for diag-v in diag-view for subview-arg = (append (subview-arg-list diag-v 'label) add-args) collect (apply #'view (append arg subview-arg)) ) collect new-views into lviews finally (setf diag-layout lviews))) (flet ((order-views (diags pairs) (loop with k = (length diags) with answer for i from 0 below (* k k) do (if (zerop (mod i (+ k 1))) (progn (push (car diags) answer) (setf diags (cdr diags))) (progn (push (car pairs) answer) (setf pairs (cdr pairs)))) finally (return (nreverse answer))))) (setf (layout-views-of self) (order-views diag-layout pair-layout)) (setf (subviews-of self) (apply #'append (layout-views-of self))) ))) (defmethod change-variable ((self pairs-layout) &key var function transform x x-function x-transform y y-function y-transform which (draw? t)) ;; changes variable its function or transform and redraws plot (if (null which) (setq which (car (or (intersection *selected-views* (subviews-of-type self 'label)) (intersection *selected-views* (subviews-of-type self 'd-view)))))) (if (typep which 'd-view) (setq which (car (vars-of which)))) (if (null which) (quail-error "Please click on subview to select old variate")) (let ((subs2 (subviews-of-type self '2d-view)) pcx pcy) (if (typep which 'label) (setq pcx (loop for p in subs2 thereis (and (member which (car (text-links-of p))) p)) pcy (loop for p in subs2 thereis (and (member which (second (text-links-of p))) p))) (setq pcx (loop for p in subs2 thereis (and (eq-variate-exprs (x-variate-of p) which) p)) pcy (loop for p in subs2 thereis (and (eq-variate-exprs (y-variate-of p) which) p)))) (when pcx (setq var (or var x y)) (setq function (or function x-function y-function)) (setq transform (or transform x-transform y-transform)) (if draw? (erase-view self)) (change-variable pcx :draw? nil :x var :x-function function :x-transform transform ) (change-variable pcy :draw? nil :y var :y-function function :y-transform transform ) (when draw? (loop for sv in (subviews-of self) do (remap-to-viewports sv :erase? nil :draw? nil)) (draw-view self)) ))) (defmethod change-case-status ((self pairs-layout) cases status &key (rescale? t) (draw? t )) (if (eq cases :selected) (setq cases (loop for v in *selected-views* append (list-viewed-elements v)))) (when cases (if draw? (erase-view self)) (loop for v in (subviews-of-type self 'd-view) do (new-case-status v (if (eq cases t) (cases-of v) cases) status :rescale? rescale? :draw? nil )) (if draw? (draw-view self)))) (defmethod activate-cases ((self pairs-layout) cases &rest args &key ) (apply #'change-case-status self cases t args)) (defmethod deactivate-cases ((self pairs-layout) cases &rest args &key ) (apply #'change-case-status self cases :ignore args)) (defmethod activate-all-cases ((self pairs-layout) &rest args &key ) (apply #'change-case-status self t t args)) (defmethod add-diagonal-views ((self pairs-layout) &key type link-bounds-x? link-bounds-y?) (let* ((pcs (loop for row in (col-format self) collect (loop for (r) in row until (typep r '2d-view) finally (return (if (typep r '2d-view) r))))) new-views ) (erase-view self) (loop for (l) in (get-view-diag self) for pc in pcs for h = (if pc (view :type type :data (dataset-of pc) :cases (cases-of pc) :var (x-variate-of pc) :function (x-func-of pc) :transform (x-transform-of pc) :variates (variates-of pc) :coords (x-coords-of pc) :linkable-bounds-x? link-bounds-x? :linkable-bounds-y? link-bounds-y? :draw? nil)) when h do (setq new-views (append new-views (list h))) (layer-subview self h l :clip-region nil :draw? nil :ignore-y? t)) (loop for v in (subviews-of self) do (remap-to-viewports v :erase? nil :draw? nil)) (draw-view self))) (defmethod get-view-diag ((self pairs-layout)) (let ((ncols (ncols-of self))) (loop with subs = (layout-views-of self) for i from 0 below (length subs) by (+ 1 ncols) collect (elt subs i)))) (defmethod nrows-of ((self pairs-layout)) (let ((lf (layout-format-of self))) (unless (listp lf) (setq lf (list nil nil))) (or (car lf) (let* ((n (length (layout-views-of self))) (ncols (cadr lf)) (nrows (if (eql ncols 0) 0 (cond ((and n ncols) (ceiling (/ n ncols))) ((<= n 1) n) (t (ceiling (sqrt n))))))) (setf (layout-format-of self) (list nrows ncols)) nrows)))) (defmethod ncols-of ((self pairs-layout)) (let ((lf (layout-format-of self))) (unless (listp lf) (setq lf (list nil nil))) (or (second lf) (let* ((n (length (layout-views-of self))) (nrows (car lf)) (ncols (if (eql nrows 0) 0 (cond ((and n nrows) (ceiling (/ n nrows))) ((<= n 1) n) (t (ceiling (sqrt n))))))) (setf (layout-format-of self) (list nrows ncols)) ncols)))) (defmethod vars-of ((self pairs-layout)) (cons (loop for a in (second (layout-views-of self)) until (typep a '2d-view) finally (if (typep a '2d-view) (return (y-variate-of a)))) (loop for v in (cdr (layout-views-of self)) for i from 0 below (- (nrows-of self) 1) collect (loop for a in v until (typep a '2d-view) finally (if (typep a '2d-view) (return (x-variate-of a))))))) (defmethod funcs-of ((self pairs-layout)) (cons (loop for a in (second (layout-views-of self)) until (typep a '2d-view) finally (if (typep a '2d-view) (return (y-func-of a)))) (loop for v in (cdr (layout-views-of self)) for i from 0 below (- (nrows-of self) 1) collect (loop for a in v until (typep a '2d-view) finally (if (typep a '2d-view) (return (x-func-of a))))))) (defmethod transforms-of ((self pairs-layout)) (cons (loop for a in (second (layout-views-of self)) until (typep a '2d-view) finally (if (typep a '2d-view) (return (y-transform-of a)))) (loop for v in (cdr (layout-views-of self)) for i from 0 below (- (nrows-of self) 1) collect (loop for a in v until (typep a '2d-view) finally (if (typep a '2d-view) (return (x-func-of a))))))) (defmethod row-views ((self pairs-layout)) (loop for row in (row-format self) collect (loop for v in (reduce #'append row) when (or (typep v '2d-view) (and (typep v '1d-view) (eql (orientation-of v) :vertical))) collect v))) (defmethod col-views ((self pairs-layout)) (loop for col in (col-format self) collect (loop for v in (reduce #'append col) when (or (typep v '2d-view) (and (typep v '1d-view) (eql (orientation-of v) :horizontal))) collect v)))
18,909
Common Lisp
.l
375
32.146667
133
0.459246
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fe0f09b8e5c45e7c9eba00dff23900302a75407d376d8311e3835c348e1c43ba
33,252
[ -1 ]
33,253
table.lsp
rwoldford_Quail/source/views/layout/table.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; table-layout.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1996 ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(table-layout proportional-height proportional-area proportional-width rescale-entries set-cell-text mosaicify))) ;;;---------------------------------------------------------------------------------- (defclass table-layout(batch-layout justification-mixin) ((scaled-dimension :initform nil :initarg :scaled-dimension :accessor scaled-dimension-of) (scales :initform nil :initarg :scales :accessor scales-of) (middle-menu :allocation :class :initform nil)) (:default-initargs :gap-x 0.02 :gap-y 0.02 :justification nil :box-views? nil :justification-menu? NIL :subview-type 'bar-with-text :default-subview-type 'bar-with-text :orientation :horizontal)) (defgeneric proportional-width(table-layout &key viewport scale &allow-other-keys) (:documentation "Make the widths of the table entries proportional to width. ~ Scale should be a list of non negative numbers, ~ one per subview.")) (defgeneric proportional-height(table-layout &key viewport scale &allow-other-keys) (:documentation "Make the heights of the table entries proportional to scale. ~ Scale should be a list of non negative numbers, ~ one per subview.")) (defgeneric proportional-area(table-layout &key viewport scale &allow-other-keys) (:documentation "Make the areas of the table entries proportional to scale. ~ Scale should be a list of non negative numbers, ~ one per subview.")) (defgeneric rescale-entries (table-layout &key viewport draw? dimension scale &allow-other-keys) (:documentation "Make the dimension specified of the table entries proportional to scale. ~ Scale should be a list of non negative numbers, ~ or a function which will be applied to the view ~ of the table entry. If scale is a number, all table entries ~ will be given the same dimension. ")) (defgeneric mosaicify (table-layout &key viewport draw? scale recursive?) (:documentation "Mosaicifies the table. ~ If recursive? is non-nil, mosaicify is applied recursively to subviews. ~ Scale should be a list of non negative numbers, ~ or a function which will be applied to the view ~ of the table entry. If scale is a number, all table entries ~ will be given the same dimension. ")) (defgeneric set-cell-text (table-layout text &key draw? ) (:documentation "Use text to display in cells")) (defmethod construct-sub-views :after (( self table-layout) &rest keyword-pairs &key cell-text) (declare (ignore keyword-pairs cell-text)) ;;(set-cell-text self cell-text :draw? nil) ) (defmethod set-cell-text (( self table-layout) bar-text &key (draw? t)) (if bar-text (if (and (listp bar-text) (= (length bar-text) (length (layout-views-of self)))) (loop for v in (layout-views-of self) for b in bar-text for l = (find '(or label text-display-mixin titled-view-mixin) v :test #'(lambda(a b) (typep b a))) when l do (if (typep l 'titled-view-mixin) (setq l (title-of l))) (setf (text-of l) b)) (loop for s in (subviews-of self) when (typep s '(or label text-display-mixin titled-view-mixin)) do (if (typep s 'titled-view-mixin) (setq s (title-of s))) (setf (text-of s) bar-text)))) (if draw? (draw-view self :erase? t))) (defmethod reshape-viewport :after ((self table-layout) vp &key new-location transform draw?) (declare (ignore new-location transform)) (rescale-entries self :viewport vp :draw? draw?)) (defmethod reposition-view :after ((self table-layout) &key default-positions draw?) (declare (ignore default-positions)) (rescale-entries self :draw? draw?)) (defmethod map-subviews-to-viewport :after ((self table-layout) &optional vp subviews) (declare (ignore subviews)) (rescale-entries self :viewport vp :draw? nil)) (defmethod rescale-entries ((self table-layout) &key viewport justification (draw? t) dimension scale) (if (eq scale :prompt) (setq scale (get-function (wb::prompt-user :result-type t :read-type :read :prompt-string "Enter scaling function, applied to each view")))) (if justification (setf (justification-of self) justification)) (if dimension (setf (scaled-dimension-of self) dimension)) (setq scale (or scale (scales-of self))) (let ( (subs (subviews-of self))) (setq scale (cond ((and scale (listp scale) (= (length scale) (length subs))) scale) ((functionp scale) (mapcar #'(lambda(v) (funcall scale v)) subs)) ((numberp scale) (make-list (length subs) :initial-element 1)) (t (mapcar #'(lambda(v) (if (typep v 'bar) (bar-count v) (length (list-cases (viewed-object-of v))))) subs)))) (setf (scales-of self) scale) (setq viewport (or viewport (car (viewports-of self)))) (if draw? (erase-view self :viewport viewport)) (case (scaled-dimension-of self) (:width (proportional-width self :viewport viewport :scale scale )) (:height (proportional-height self :viewport viewport :scale scale )) (:area (proportional-area self :viewport viewport :scale scale )) (t (setq draw? nil))) (loop for sv in (subviews-of self) do (map-to-viewport sv (select-viewport sv viewport))) (when draw? ;; (draw-view self :erase? nil :viewport viewport) (draw-view self :erase? nil :viewport viewport)))) (defmethod proportional-width ((self table-layout) &key viewport scale) (let ((max-c 0) fac tr l max-w (just (justification-of self)) (subs (subviews-of self)) (nr (nrows-of self)) (nc (ncols-of self)) (gap-x (getf (default-positions-of self) :gap-x)) (gap-vp )) (if (eq just :free) (progn (setq max-c (loop with s = scale for i from 0 below nr maximize (loop for j from 0 below nc sum (car s) do (setf s (cdr s))))) (loop for vport in (enlist-viewport self viewport) do (setq tr (select-map-to-viewport self vport)) (setq l (car (sub-view-locns-of self))) (setq max-w (if l (* nc (width-of (apply-transform tr l))) (width-of vport))) ;;(setq gap-vp (ceiling (* gap-x (/ max-w nc)))) (setq gap-vp (round (* gap-x (/ max-w nc)))) (unless (zerop gap-x) (setq gap-vp (max gap-vp 1))) (setf fac (/ max-w max-c)) (loop with vp-left with left with right for v in subs for c in scale for i upfrom 0 for col = (mod i nc) for w = (round (* fac c )) for l in (sub-view-locns-of self) for vp = (select-viewport v vport) do (if (and (= i 0) (null left)) (setq left (round (left-of (apply-transform tr l))))) (if (and (null right) (= i (- nc 1))) (setq right (round (right-of (apply-transform tr l))))) (cond ((= col 0) (setf (left-of vp) left) (setf (right-of vp) (+ (left-of vp) w ))) (t (setf vp-left (select-viewport (nth (- i 1) subs) vport)) (setf (left-of vp) (+ (right-of vp-left) gap-vp)) (setf (right-of vp) (if (= col (- nc 1)) right (+ (left-of vp) w )))))))) (progn (setq max-c (apply #'max scale)) (unless (<= max-c 0) (loop for vport in (enlist-viewport self viewport) do (setq tr (select-map-to-viewport self vport)) (setq l (car (sub-view-locns-of self))) (setq max-w (truncate (if l (width-of (apply-transform tr l)) (/ (width-of vport) (ncols-of self))))) (setf fac (/ max-w max-c)) (loop with vp1 = (make-viewport (window-of vport)) for v in subs for c in scale for w = (round (* fac c )) for l in (sub-view-locns-of self) for vp = (select-viewport v vport) for h = (height-of vp) do (setf (bounds-of vp1) (apply-transform tr l)) (case just (:bottom (setf (bottom-of vp) (bottom-of vp1)) (setf (top-of vp) (+ (bottom-of vp) h )) (set-viewport-width-height vp w nil)) (:top (setf (top-of vp) (top-of vp1)) (setf (bottom-of vp) (- (top-of vp) h )) (set-viewport-width-height vp w nil)) (:left (setf (left-of vp) (left-of vp1)) (setf (right-of vp) (+ (left-of vp) w))) (:right (setf (right-of vp) (right-of vp1)) (setf (left-of vp) (- (right-of vp) w)) (setf (height-of vp) h)) (t (set-viewport-width-height vp w h))) ) )) )) )) (defmethod proportional-height ((self table-layout) &key viewport scale) (let ( (max-c 0) fac tr l max-h (just (justification-of self)) (subs (subviews-of self)) (nr (nrows-of self)) (nc (ncols-of self)) (gap-y (getf (default-positions-of self) :gap-y)) gap-vp) (if (eq just :free) (progn (setq max-c (loop for j from 0 below nc maximize (loop for i from 0 below nr sum (nth (+ j (* i nc)) scale) ))) (loop for vport in (enlist-viewport self viewport) do (setq tr (select-map-to-viewport self vport)) (setq l (car (sub-view-locns-of self))) (setq max-h (if l (* nr (height-of (apply-transform tr l))) (height-of vport))) ;; (setq gap-vp (ceiling (* gap-y (/ max-h nr)))) (setq gap-vp (round (* gap-y (/ max-h nr)))) (unless (zerop gap-y) (setq gap-vp (max gap-vp 1))) (setf fac (/ max-h max-c)) (loop with vp-above with top for v in subs for c in scale for i upfrom 0 for row = (truncate i nc) for h = (round (* fac c )) for l in (sub-view-locns-of self) for vp = (select-viewport v vport) do (if (= i 0) (setq top (round (top-of (apply-transform tr l))))) (cond ((= row 0) (setf (top-of vp) top) (setf (bottom-of vp) (- (top-of vp) h ))) (t (setf vp-above (select-viewport (nth (- i nc) subs) vport)) (setf (top-of vp) (- (bottom-of vp-above) gap-vp)) (setf (bottom-of vp) (- (top-of vp) h ))))))) (progn (setq max-c (apply #'max scale)) (unless (<= max-c 0) (loop for vport in (enlist-viewport self viewport) do (setq tr (select-map-to-viewport self vport)) (setq l (car (sub-view-locns-of self))) (setq max-h (truncate (if l (height-of (apply-transform tr l)) (/ (height-of vport) nr)))) (setf fac (/ max-h max-c)) (loop with vp1 = (make-viewport (window-of vport)) for v in subs for c in scale for h = (round (* fac c )) for l in (sub-view-locns-of self) for vp = (select-viewport v vport) for w = (width-of vp) do (setf (bounds-of vp1) (apply-transform tr l)) (case just (:bottom (setf (bottom-of vp) (bottom-of vp1)) (setf (top-of vp) (+ (bottom-of vp) h ))) (:top (setf (top-of vp) (top-of vp1)) (setf (bottom-of vp) (- (top-of vp) h ) )) (:left (setf (left-of vp) (left-of vp1)) (setf (right-of vp) (+ (left-of vp) w)) (set-viewport-width-height vp nil h)) (:right (setf (right-of vp) (right-of vp1)) (setf (left-of vp) (- (right-of vp) w)) (set-viewport-width-height vp nil h)) (t (set-viewport-width-height vp w h)))) )))))) (defmethod justification-of ((self table-layout)) (let ((j (slot-value self 'justification))) (if (null j) (cond ((= 1 (nrows-of self)) :bottom) ((= 1 (ncols-of self)) :left) (t :center)) j))) (defmethod proportional-area ((self table-layout) &key viewport scale) (let ((size (mapcar #'sqrt scale))) (proportional-width self :viewport viewport :scale size) (proportional-height self :viewport viewport :scale size))) (defmethod get-menu-items ((self table-layout) (slot-name (eql 'middle-menu))) '(("-" nil) ( "Justification" (set-subview-justification :prompt :draw? T) "Prompt for a change in the justification of the text.") ("Width" nil "" :sub-items (("Proportional" (rescale-entries :dimension :width )) ("Proportional to" (rescale-entries :dimension :width :scale :prompt )) ("Constant" (rescale-entries :dimension :width :scale 1)))) ("Height" nil "" :sub-items (("Proportional" (rescale-entries :dimension :height )) ("Proportional to" (rescale-entries :dimension :height :scale :prompt)) ("Constant" (rescale-entries :dimension :height :scale 1)))) ("Area" nil "" :sub-items (("Proportional" (rescale-entries :dimension :area )) ("Proportional to" (rescale-entries :dimension :area :scale :prompt)) ("Constant" (rescale-entries :dimension :area :scale 1 )))) ("Mosaic" nil "" :sub-items (("Proportional" (mosaicify )) ("Proportional to" (mosaicify :scale :prompt)) ("Constant" (mosaicify :scale 1 )))) )) (defmethod set-subview-justification ((self table-layout) justification &key (draw? nil) ) (if (eq :prompt justification) (setq justification (car (wb:prompt-for-items (list :center :left :right :bottom :top ) :prompt-text "Choose subview justification")))) (rescale-entries self :draw? draw? :justification justification) (loop for s in (subviews-of self) when (and (typep s 'justification-mixin) (member justification (list-legal-justifications s))) do (set-justification s justification :draw? draw?))) (defmethod mosaicify ((self table-layout) &key scale (draw? t) viewport (recursive? t)) (setq viewport (or viewport (car (viewports-of self)))) (if (eq scale :prompt) (setq scale (get-function (wb::prompt-user :result-type t :read-type :read :prompt-string "Enter scaling function, applied to each view")))) (if draw? (erase-view self :viewport viewport)) (cond ((= 1 (ncols-of self)) (rescale-entries self :dimension :height :scale scale :justification :free :draw? nil)) ((= 1 (nrows-of self)) (rescale-entries self :dimension :width :scale scale :justification :free :draw? nil)) (t (rescale-entries self :dimension :area :scale scale :justification :center :draw? nil))) (if recursive? (loop for b in (subviews-of self) when (typep b 'table-layout) do (mosaicify b :scale scale :draw? nil :viewport (select-viewport b viewport) ))) (when draw? ;; (draw-view self :erase? nil :viewport viewport) (draw-view self :erase? nil :viewport viewport)))
19,291
Common Lisp
.l
358
36.51676
152
0.486317
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6342e45234dc242b31aa9361cd1445525287842852302ee83742ea383431d5ad
33,253
[ -1 ]
33,254
view-layers.lsp
rwoldford_Quail/source/views/layout/view-layers.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; view-layers.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1993 George Washington University ;;; ;;; ;;; ;;;------------------------------------------------ (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(view-layers))) (defclass view-layers(compound-view) ((link-bounds-x? :initform t :initarg :link-bounds-x? :accessor link-bounds-x-p) (link-bounds-y? :initform t :initarg :link-bounds-y? :accessor link-bounds-y-p)) ) (defmethod construct-sub-views ((self view-layers) &rest keyword-pairs &key nsubviews subviews subview-type) (labels ((repeat-list(list n) (if (and list n) (loop while (< (length list) n) do (setq list (append list list)) finally (return (subseq list 0 n))) list)) (local-make-view(arg &optional type) (if (view-p arg) arg (apply #'view (append (if type (list :type type)) (subview-arg-list arg) keyword-pairs))))) (if (and (null nsubviews) (numberp subviews)) (rotatef nsubviews subviews)) (if (and subviews (not (listp subviews))) (setq subviews (list subviews))) (setq subviews (cond ((and subviews (listp subviews)) (repeat-list subviews nsubviews)) ((and (numberp nsubviews) (null subview-type)) (repeat-list (choose-views-from-menu :prompt-string "Select layer views" :superclass '(or simple-view compound-view) :nmax nsubviews) nsubviews)) ((numberp nsubviews) (make-list nsubviews)) ((and (null subviews) (null subview-type)) (choose-views-from-menu :superclass '(or simple-view compound-view) :prompt-string "Select layer views" )) (t nil))) (loop for key in '(:subviews :subview-type) do (disable-keyword keyword-pairs key)) (setf (subviews-of self) (loop for s in subviews collect (if (legal-view-construct-p s) (local-make-view s subview-type) (quail-error "Illegal subview argument ~A" s)))) (constrain-bounds self))) (defmethod init-position-subviews ((self view-layers) &key ) (let ((br (bounding-region-of self))) (setf (sub-view-locns-of self) (loop repeat (length (subviews-of self)) collect (make-region br))))) (defmethod constrain-bounds ((self view-layers) &key draw? (link-bounds-x? :ignore) (link-bounds-y? :ignore)) (unless (eq link-bounds-x? :ignore) (setf (link-bounds-x-p self) link-bounds-x?)) (unless (eq link-bounds-y? :ignore) (setf (link-bounds-y-p self) link-bounds-y?)) (if (link-bounds-x-p self) (link-view-bounds (subviews-of self) :x)) (if (link-bounds-y-p self) (link-view-bounds (subviews-of self) :y)) (when (or (link-bounds-x-p self) (link-bounds-y-p self)) (remap-to-viewports self :erase? draw? :draw? draw?)))
3,969
Common Lisp
.l
86
33.302326
92
0.496971
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
913657cc0571aca63f956a8b0bf55fb5aecd14b5e82f15ce70a8a0a247edac76
33,254
[ -1 ]
33,255
grid-layout.lsp
rwoldford_Quail/source/views/layout/grid-layout.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; grid-layout.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;------------------------------------------------ (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(set-format row-format col-format grid-layout batch-layout grid-position-subviews *default-grid-gap*))) (defvar *default-grid-gap* ) (setq *default-grid-gap* 0.1) (defgeneric grid-position-subviews (view &key &allow-other-keys)) (defgeneric set-format (grid-layout &key &allow-other-keys)) (defgeneric row-format (grid-layout) (:documentation "Returns lists of views in layout with ~ sublist i containing views in row i.")) (defgeneric col-format (grid-layout) (:documentation "Returns lists of views in layout with ~ sublist i containing views in column i.")) (defclass grid-layout(position-key-mixin view-layout ) ((position-keys :initform '(:gap-x :gap-y :rows :cols ) :allocation :class) (layout-format :initform nil :accessor layout-format-of :initarg :format) (right-menu :allocation :class :initform nil) ) (:default-initargs :gap-x *default-grid-gap* :gap-y *default-grid-gap* :square? nil :format :grid :link-bounds-x? nil :link-bounds-y? nil :box-views? t :subview-position-fn #'grid-position-subviews)) (defmethod construct-sub-views :around ((self grid-layout) &rest keyword-pairs &key rows cols nrows ncols format) (setq nrows (cond ((eq format :row) 1) ((and rows (listp rows)) (truncate (length rows) 2)) ((and rows (numberp rows)) rows) (t nrows))) (setq ncols (cond ((eq format :col) 1) ((and cols (listp cols)) (truncate (length cols) 2)) ((and cols (numberp cols)) cols) (t ncols))) (if (and nrows ncols) (apply #'call-next-method self :nsubviews (* nrows ncols) keyword-pairs) (call-next-method))) (defmethod set-format ((self grid-layout) &key rows cols nrows ncols format) (let ((n (length (layout-views-of self))) (lf (layout-format-of self))) (unless (and lf (listp lf) (= 2 (length lf)) (and (numberp (car lf)) (numberp (second lf))) (<= n (* (car (layout-format-of self)) (cadr (layout-format-of self))))) (case format (:row (setf (layout-format-of self) (list 1 n))) (:col (setf (layout-format-of self) (list n 1))) (t (setq nrows (cond ((and rows (listp rows)) (truncate (length rows) 2)) ((and rows (numberp rows)) rows) (t nrows))) (setq ncols (cond ((and cols (listp cols)) (truncate (length cols) 2)) ((and cols (numberp cols)) cols) (t ncols))) (if (or nrows ncols) (setf (layout-format-of self) (list nrows ncols))) (setq nrows (nrows-of self)) (setq ncols (ncols-of self)) (loop while (< (* nrows ncols) n) do (setf (layout-format-of self) nil) (setq nrows (nrows-of self)) (setq ncols (ncols-of self))) (if (> (* nrows ncols) n) (loop repeat (- (* nrows ncols) n) for view = (view) collect (list view) into lviews collect view into sviews finally (setf (subviews-of self) (append (subviews-of self) sviews)) (setf (layout-views-of self) (append (layout-views-of self) lviews)))) ))))) (defmethod init-position-subviews :before ((self grid-layout) &rest keyword-pairs &key gap-x gap-y rows cols) (apply #'set-format self keyword-pairs) (if (eq gap-y :prompt) (setf (getf (default-positions-of self) :gap-y) (if (or (and rows (listp rows)) (= (nrows-of self) 1)) 0 (wb:prompt-user :result-type 'number :read-type :eval :prompt-string (format nil "Vertical gap, as a fraction of height?"))))) (if (eq gap-x :prompt) (setf (getf (default-positions-of self) :gap-x) (if (or (and cols (listp cols)) (= (ncols-of self) 1)) 0 (wb:prompt-user :result-type 'number :read-type :eval :prompt-string (format nil "Horizontal gap, as a fraction of width?")))))) (defmethod grid-position-subviews ((self grid-layout) &key rows cols square? bounding-region) (let ((subs (layout-views-of self)) (big-region (subview-position-region self)) sub-regions all-regions (r (nrows-of self)) (c (ncols-of self)) (gap-x (getf (default-positions-of self) :gap-x)) (gap-y (getf (default-positions-of self) :gap-y))) (when subs (setq sub-regions (tile-region-list big-region r c (if (or rows cols) nil square?) gap-x gap-y)) (if cols (loop for reg in sub-regions for i upfrom 0 for j = (* 2 (mod i c)) do (setf (left-of reg) (elt cols j)) (setf (right-of reg) (elt cols (1+ j))))) (if rows (loop for reg in sub-regions for i upfrom 0 for j = (* 2 (truncate i c)) do (setf (top-of reg) (elt rows j)) (setf (bottom-of reg) (elt rows (1+ j))))) (loop for views in subs for r in sub-regions do (loop repeat (length views) do (push (make-region r) all-regions))) (setf (sub-view-locns-of self) (nreverse all-regions)) (setf (sub-views-of self) (reduce #'append subs))) (if (null bounding-region) (set-bounding-region self :region (cond ((and rows cols) (make-region (first cols) (car (last cols)) (car (last rows)) (first rows) )) (rows (make-region 0 1 (car (last rows)) (first rows) )) (cols (make-region (first cols) (car (last cols)) 0 1)) (t (make-region))))) (constrain-bounds self ))) (defmethod equate-hist-bins ((self grid-layout) &key (draw? nil)) (if (link-bounds-x-p self) (loop for views in (case (link-bounds-x-p self) (:by-row (row-format self)) (:by-col (col-format self)) (t (list (apply #'nconc (row-format self))))) for hists = (loop for v in (flatten-views views) when (and (typep v 'histogram-view) (break-points-of v) (eql (orientation-of v) :horizontal)) collect v) when hists do (let* ((hist1 (car hists)) (br (bounding-region-of hist1)) (nbins (- (length (break-points-of hist1)) 1)) (breaks (compute-bins (left-of br) (right-of br) nbins))) (with-constrained-extent hists :x draw? (loop for h in hists do (new-sub-views h :break-points breaks) (init-position-subviews h) (set-bounding-region h )))))) (if (link-bounds-y-p self) (loop for views in (case (link-bounds-y-p self) (:by-row (row-format self)) (:by-col (col-format self)) (t (list (apply #'nconc (row-format self))))) for hists = (loop for v in (flatten-views views) when (and (typep v 'histogram-view) (break-points-of v) (eql (orientation-of v) :vertical)) collect v) when hists do (let* ((hist1 (car hists)) (br (bounding-region-of hist1)) (nbins (- (length (break-points-of hist1)) 1)) (breaks (compute-bins (bottom-of br) (top-of br) nbins))) (with-constrained-extent hists :y draw? (loop for h in hists do (new-sub-views h :break-points breaks) (init-position-subviews h) (set-bounding-region h ))))))) (defmethod proportional-boxp-bars ((self grid-layout) &key (draw? nil)) (let ((redraw-views nil)) (if (link-bounds-x-p self) (loop for views in (case (link-bounds-x-p self) (:by-row (row-format self)) (:by-col (col-format self)) (t (list (apply #'nconc (row-format self))))) for boxps = (loop for v in (flatten-views views) when (and (typep v 'boxplot-view) (equal-areas-p v) (eql (orientation-of v) :vertical)) collect v) when boxps do (let ((mcpu (loop for b in boxps for mc = (max-count-per-unit b) when mc maximize mc))) (when mcpu (loop for b in boxps do (proportional-bar-widths b mcpu)))) (if draw? (setq redraw-views (append redraw-views boxps ))))) (if (link-bounds-y-p self) (loop for views in (case (link-bounds-y-p self) (:by-row (row-format self)) (:by-col (col-format self)) (t (list (apply #'nconc (row-format self))))) for boxps = (loop for v in (flatten-views views) when (and (typep v 'boxplot-view) (equal-areas-p v) (eql (orientation-of v) :horizontal)) collect v) when boxps do (let ((mcpu (loop for b in boxps for mc = (max-count-per-unit b) when mc maximize mc))) (when mcpu (loop for b in boxps do (proportional-bar-widths b mcpu)))) (if draw? (setq redraw-views (append redraw-views boxps ))))) (if draw? (loop for v in redraw-views do (remap-to-viewports v :erase? t :draw? draw?))))) (defmethod constrain-bounds ((self grid-layout) &key draw? (link-bounds-x? :ignore) (link-bounds-y? :ignore)) (unless (eq link-bounds-x? :ignore) (setf (link-bounds-x-p self) link-bounds-x?)) (unless (eq link-bounds-y? :ignore) (setf (link-bounds-y-p self) link-bounds-y?)) (if (eq (link-bounds-x-p self) :prompt) (setf (link-bounds-x-p self) (cadar (wb:prompt-for-items '(("No link" nil) ("Link all" t) ("By row" :by-row) ("By col" :by-col)) :prompt-text "Link-bounds-X?" :item-function #'first)))) (if (eq (link-bounds-y-p self) :prompt) (setf (link-bounds-y-p self) (cadar (wb:prompt-for-items '(("No link" nil) ("Link all" t) ("By row" :by-row) ("By col" :by-col)) :prompt-text "Link-bounds-Y?" :item-function #'first)))) (setq link-bounds-x? (link-bounds-x-p self)) (setq link-bounds-y? (link-bounds-y-p self)) (if link-bounds-x? (loop for views in (case link-bounds-x? (:by-row (row-views self)) (:by-block-row (merge-rows self)) (:by-block-col (merge-cols self)) (:by-col (col-views self)) (t (list (apply #'append (row-views self))))) for x-views = (loop for v in views when (linkable-bounds-x-p v) collect v) for d-views = (loop for v in x-views when (and (typep v 'd-view) (use-x-axis-p v)) collect v) when (> (length x-views) 1) do (link-view-bounds x-views :x) (set-view-extents x-views :x :region (if d-views (maximize-x-extents d-views)) :recompute? nil ))) (if link-bounds-y? (loop for views in (case link-bounds-y? (:by-row (row-views self)) (:by-block-row (merge-rows self)) (:by-block-col (merge-cols self)) (:by-col (col-views self)) (t (list (apply #'append (row-views self))))) for y-views = (loop for v in (flatten-views views) when (linkable-bounds-y-p v) collect v) for d-views = (loop for v in y-views when (and (typep v 'd-view) (use-y-axis-p v)) collect v) when (> (length y-views) 1) do (link-view-bounds y-views :y) (set-view-extents y-views :y :recompute? nil :region (if d-views (maximize-y-extents d-views))))) (equate-hist-bins self) (proportional-boxp-bars self) (when (or link-bounds-x? link-bounds-y?) (remap-to-viewports self :erase? draw? :draw? draw?))) (defmethod change-variable :after ((self grid-layout) &key draw?) (proportional-boxp-bars self :draw? draw?) (equate-hist-bins self :draw? draw?)) (defmethod get-view-row ((self grid-layout) row) (let ((ncols (ncols-of self))) (subseq (layout-views-of self) (* row ncols) (min (length (subviews-of self)) (* (+ 1 row) ncols))))) (defmethod get-view-col ((self grid-layout) col) (let ((ncols (ncols-of self))) (loop with subs = (layout-views-of self) for i from col below (length subs) by ncols collect (elt subs i)))) (defmethod nrows-of ((self grid-layout)) (let ((lf (layout-format-of self))) (unless (listp lf) (setq lf (list nil nil))) (or (car lf) (let* ((n (length (layout-views-of self))) (ncols (second lf)) (nrows (cond ((eq ncols 0) 0) (ncols (ceiling n ncols)) ((<= n 1) n) (t (wb:prompt-user :type 'number :read-type :eval :prompt-string (format nil "~S views, how many rows?" n)))))) (setf (layout-format-of self) (list nrows ncols)) nrows)))) (defmethod ncols-of ((self grid-layout)) (let ((lf (layout-format-of self))) (unless (listp lf) (setq lf (list nil nil))) (or (second lf) (let* ((n (length (layout-views-of self))) (nrows (car lf)) (ncols (cond ((eq nrows 0) 0) (nrows (ceiling n nrows)) ((<= n 1) n) (t (wb:prompt-user :type 'number :read-type :eval :prompt-string (format nil "~S views, how many columns?" n)))))) (setf (layout-format-of self) (list nrows ncols)) ncols)))) (defmethod row-format ((self grid-layout)) (loop with nrows = (nrows-of self) with ncols = (ncols-of self) with evs = (layout-views-of self) for i from 0 below nrows collect (loop for j below ncols collect (car evs) do (setf evs (cdr evs))))) (defmethod col-format ((self grid-layout)) (apply #'mapcar #'list (row-format self))) (defmethod allowed-subview-movement ((self grid-layout) subview) (declare (ignore subview)) :none) (defmethod use-x-axis-p ((self grid-layout)) nil) (defmethod use-y-axis-p ((self grid-layout)) nil) #| (defmethod grid-margin-region-info ((self grid-layout) (axis (eql :vertical)) index) (let* ((views (get-view-row self index)) (v (loop for vi in (flatten-views views) until (typep vi '2d-view) finally (return vi)))) (if v (if (typep v 'd-view) (smallest-bounding-region v) (bounding-region-of v)) ))) (defmethod grid-margin-region-info ((self grid-layout) (axis (eql :horizontal)) index) (let* ((views (get-view-col self index)) (v (loop for vi in (flatten-views views) until (typep vi '2d-view) finally (return vi)))) (if v (if (typep v 'd-view) (smallest-bounding-region v) (bounding-region-of v)) ))) |# (defmethod coord-string-x ((self grid-layout)) (loop for views in (col-format self) for vf = (flatten-views views) collect (or (loop for vi in vf thereis (and (typep vi '2d-view) (coord-string-x vi))) (loop for vi in vf thereis (and (typep vi '1d-view) (coord-string vi))) (loop for vi in vf thereis (coord-string-x vi)) ""))) (defmethod coord-string-y ((self grid-layout)) (loop for views in (row-format self) for vf = (flatten-views views) collect (or (loop for vi in vf thereis (and (typep vi '2d-view) (coord-string-y vi))) (loop for vi in vf thereis (and (typep vi '1d-view) (coord-string vi))) (loop for vi in vf thereis (coord-string-y vi)) ""))) (defmethod row-views ((self grid-layout)) (if (subviews-of self) (loop with new for views in (row-format self) for v = (remove nil (mapcar #'row-views (reduce #'append views))) for n = (length (car v)) when (every #'(lambda(x) (= (length x) n)) (cdr v)) do (setq new (make-list n )) and append (loop for vi in v do (loop for vij in vi for j upfrom 0 do (setf (nth j new) (append (nth j new) vij))) finally (return new))))) (defmethod col-views ((self grid-layout)) (if (subviews-of self) (loop with new for views in (col-format self) for v = (remove nil (mapcar #'col-views (reduce #'append views))) for n = (length (car v)) when (every #'(lambda(x) (= (length x) n)) (cdr v)) do (setq new (make-list n )) and append (loop for vi in v do (loop for vij in vi for j upfrom 0 do (setf (nth j new) (append (nth j new) vij))) finally (return new))))) (defmethod merge-rows ((self grid-layout)) (let* ((rows (row-views self)) (nrows (length rows)) (nblocks (nrows-of self)) (rows-per-block (ceiling nrows nblocks))) (loop with new = (make-list rows-per-block) for r in rows for i upfrom 0 for j = (mod i rows-per-block) do (setf (nth j new) (append (nth j new) r)) finally (return new)))) (defmethod merge-cols ((self grid-layout)) (let* ((cols (col-views self)) (ncols (length cols)) (nblocks (ncols-of self)) (cols-per-block (ceiling ncols nblocks))) (loop with new = (make-list cols-per-block) for r in cols for i upfrom 0 for j = (mod i cols-per-block) do (setf (nth j new) (append (nth j new) r)) finally (return new)))) #| (defmethod merge-rows ((self grid-layout)) (loop with all = (loop for views in (row-format self) collect (mapcar #'row-views (reduce #'append views))) with n = (loop for v in all maximize (apply #'max (mapcar #'length v))) with new = (make-list n ) for views in all do (loop for vi in views do (loop for vij in vi for j upfrom 0 do (setf (nth j new) (append (nth j new) vij)))) finally (return new))) (defmethod merge-cols ((self grid-layout)) (loop with all = (loop for views in (col-format self) collect (mapcar #'col-views (reduce #'append views))) with n = (loop for v in all maximize (apply #'max (mapcar #'length v))) with new = (make-list n ) for views in all do (loop for vi in views do (loop for vij in vi for j upfrom 0 do (setf (nth j new) (append (nth j new) vij)))) finally (return new))) |#
22,755
Common Lisp
.l
492
31.00813
147
0.480121
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
675825d77b29a3c88e40d5c4809547c693228cfab7195d9911a8e146197924c0
33,255
[ -1 ]
33,256
1d-layout.lsp
rwoldford_Quail/source/views/layout/1d-layout.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; 1d-layout.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(1d-layout 1d-sub-views ))) (defgeneric 1d-sub-views (view-layout &key &allow-other-keys)) (defclass 1d-layout (grid-layout) () (:default-initargs :subview-superclass '1d-view :link-bounds-x? t :link-bounds-y? t :format :row :initform-fn #'get-data-inits :common-vars? nil :subview-constructor #'1d-sub-views :common-case-views? :default)) (defmethod coord-string-x ((self 1d-layout)) (cond ((= 1 (ncols-of self)) (list (or (loop for vi in (subviews-of self) thereis (and (typep vi '1d-view) (free-coord-string vi))) ""))) ((= 1 (nrows-of self)) (loop for views in (col-format self) for vf = (flatten-views views) collect (or (loop for vi in vf thereis (coord-string vi)) ""))) (t (call-next-method)))) (defmethod coord-string-y ((self 1d-layout)) (cond ((= 1 (nrows-of self)) (list (or (loop for vi in (subviews-of self) thereis (and (typep vi '1d-view) (free-coord-string vi))) ""))) ((= 1 (ncols-of self)) (loop for views in (row-format self) for vf = (flatten-views views) collect (or (loop for vi in vf thereis (coord-string vi)) ""))) (t (call-next-method)))) (defmethod 1d-sub-views ((self view-layout) &rest keyword-pairs &key subview-type subview-superclass subviews common-case-views? (cases #'list-cases) vars functions transforms (value-fn #'value-of) format orientation) (let* ((n (length vars)) (fns (or functions (make-list n :initial-element nil))) (trans (or transforms (make-list n ))) (dir (or orientation (if (eq format :row) :vertical :horizontal)))) (if (eql common-case-views? :default) (setq common-case-views? (not subviews))) (labels ((set-subview-type() (or subview-type (setq subview-type (choose-views-from-menu :prompt-string "Select 1d views" :superclass subview-superclass)))) (add-var(s v f tr) (let ((vlist (list :var v :function f :transform tr :cases cases :value-fn value-fn :orientation dir))) (cond ((typep s 'view) s) ((and (listp s) (getf s :type)) (append s vlist)) ((listp s) (set-subview-type) (append s vlist)) (t (append (list :type s) vlist)))))) (unless (or subviews subview-type) (set-subview-type)) (when vars (cond ((and subviews (= (length subviews) (length vars))) (setq subviews (loop for v in vars for f in fns for tr in trans for s in subviews collect (cond ((legal-view-construct-p s) (add-var s v f tr)) ((listp s) (loop for si in s collect (add-var si v f tr))) (t (add-var nil v f tr))))) ) (t (setq subviews (loop for v in vars for f in fns for tr in trans collect (list :var v :function f :transform tr :cases cases :orientation dir)))))) )) (apply #'default-layout-sub-views self :subviews subviews :nsubviews nil :subview-type subview-type :common-case-views? common-case-views? keyword-pairs) ) (defmethod vars-of ((self 1d-layout)) (loop for v in (layout-views-of self) for vi = (loop for vi in v thereis (and (typep vi '1d-view) vi)) collect (if vi (variate-of vi)))) (defmethod funcs-of ((self 1d-layout)) (loop for v in (layout-views-of self) for vi = (loop for vi in v thereis (and (typep vi '1d-view) vi)) collect (if vi (func-of vi)))) (defmethod transforms-of ((self 1d-layout)) (loop for v in (layout-views-of self) for vi = (loop for vi in v thereis (and (typep vi '1d-view) vi)) collect (if vi (transform-of vi))))
5,748
Common Lisp
.l
130
29.053846
97
0.44765
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ace6eb640a91c4a89bb82fa6582bfc3de6f8be3a875fdcdfdc9a0ce7a3615ce9
33,256
[ -1 ]
33,257
xy-layout.lsp
rwoldford_Quail/source/views/layout/xy-layout.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; xy-layout.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1995 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(xy-layout xy-sub-views))) (defclass xy-layout (grid-layout) ((middle-menu :allocation :class :initform nil)) (:default-initargs :box-views? t :subview-superclass '2d-view :gap-x 0 :gap-y 0 :link-bounds-x? :by-col :link-bounds-y? :by-row :initform-fn #'get-data-inits-xy :subview-constructor #'xy-sub-views :common-case-views? :default )) (defgeneric xy-sub-views (view-layout &key &allow-other-keys)) (defmethod construct-sub-views :after ((self xy-layout) &key x-vars y-vars) (setf (layout-format-of self) (list (length y-vars) (length x-vars)))) (defmethod xy-sub-views ((self xy-layout) &rest keyword-pairs &key subview-type subview-superclass subviews common-case-views? (cases #'list-cases) (value-fn #'value-of) x-vars y-vars x-functions x-transforms y-functions y-transforms ) (setq x-functions (or x-functions (make-list (length x-vars)))) (setq y-functions (or y-functions (make-list (length y-vars)))) (setq x-transforms (or x-transforms (make-list (length x-vars)))) (setq y-transforms (or y-transforms (make-list (length y-vars)))) (if (eql common-case-views? :default) (setq common-case-views? (not subviews))) (labels ((set-subview-type() (or subview-type (setq subview-type (choose-views-from-menu :prompt-string "Select xy view(s)" :superclass subview-superclass)))) (add-var(s x-list y-list) (let ((vlist (append x-list y-list (list :cases cases :value-fn value-fn)))) (cond ((typep s 'view) s) ((and (listp s) (getf s :type)) (append s vlist)) ((listp s) (set-subview-type) (append s vlist)) (t (append (list :type s) vlist)) )))) (unless (or subviews subview-type) (set-subview-type)) (when (and x-vars y-vars) (cond ((and subviews (= (length subviews) (* (length x-vars) (length y-vars)))) (setq subviews (loop with i = 0 for y in y-vars for yf in y-functions for yt in y-transforms for y-list = (list :y y :y-function yf :y-transform yt) append (loop for x in x-vars for xf in x-functions for xt in x-transforms for s = (nth i subviews) for x-list = (list :x x :x-function xf :x-transform xt) collect (cond ((legal-view-construct-p s) (add-var s x-list y-list)) ((listp s) (loop for si in s collect (add-var si x-list y-list))) (t (add-var nil x-list y-list))) do (incf i)))) ) (t (setq subviews (loop for y in y-vars for yf in y-functions for yt in y-transforms for y-list = (list :y y :y-function yf :y-transform yt :cases cases) append (loop for x in x-vars for xf in x-functions for xt in x-transforms collect (append (list :x x :x-function xf :x-transform xt) y-list )))) ))) ) (apply #'default-layout-sub-views self :subviews subviews :nsubviews nil :subview-type subview-type :common-case-views? common-case-views? keyword-pairs))
4,938
Common Lisp
.l
100
32.73
105
0.454526
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
063c03572962bf12d9119a78e84145b3c966ce87f3eeec7e39161c5f711259c3
33,257
[ -1 ]
33,258
case-layout.lsp
rwoldford_Quail/source/views/layout/case-layout.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; case-layout.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1996 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; case-layout.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Views system, a toolkit for interactive statistical graphics. ;;; ;;; ;;; Authors: ;;; C.B. Hurley 1992 George Washington University ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :views) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(case-layout ))) (defclass case-layout (grid-layout) () (:default-initargs :subview-type '1d-point-cloud :default-subview-type '1d-point-cloud :link-bounds-x? t :link-bounds-y? t :format :col :initform-fn #'get-data-inits-1 :common-vars? t :common-case-views? nil :subview-constructor #'case-layout-sub-views)) (defgeneric case-layout-sub-views (view-layout &key &allow-other-keys)) (defmethod case-layout-sub-views ((self view-layout) &rest keyword-pairs &key subview-type subview-superclass subviews data (labels #'identifier-name) (cases #'list-cases) (common-case-views? t) (common-vars? nil) format orientation) (let* ( (dir (or orientation (if (eq format :row) :vertical :horizontal))) var-args) (setq cases (cases-of self)) (setq var-args (loop with var-keys = (list :vars :functions :transforms :var :function :transform :x :x-function :x-transform :y :y-function :y-transform :z :z-function :z-transform ) for key in keyword-pairs by #'cddr for val in (cdr keyword-pairs) by #'cddr when (member key var-keys) collect key and collect val )) (setq var-args (append (list :orientation dir :data data) var-args)) (labels ((set-subview-type() (or subview-type (setq subview-type (choose-views-from-menu :prompt-string "Select 1d views" :superclass subview-superclass)))) (add-arg( arg s) (cond ((null s) (append var-args arg)) ((typep s 'view) s) ((and (listp s) (getf s :type)) (append s var-args arg)) ((listp s) (append s var-args arg (list :type (set-subview-type) ))) (t (cons s (append var-args var-args )))))) (unless (or subviews subview-type) (set-subview-type)) (when cases (setq subviews (cond ((and subviews (listp subviews)) (if (legal-view-construct-p subviews) (setq subviews (list subviews))) (loop for s in cases for l in (if (listp labels) labels (make-list (length cases) :initial-element labels)) for list-s = `(:cases ,(list s) :labels ,(list l)) collect (loop for sub in subviews for legal = (legal-view-construct-p sub) collect (cond (legal (add-arg list-s sub)) (t nil))))) (t (loop for s in cases for l in (if (listp labels) labels (make-list (length cases) :initial-element labels)) for list-s = `(:cases ,(list s) :labels ,(list l)) collect (add-arg list-s nil)))))) (apply #'default-layout-sub-views self :subviews subviews :nsubviews nil :subview-type subview-type :common-case-views? common-case-views? :common-vars? common-vars? keyword-pairs)) )) (defmethod margin-string-left ((self case-layout)) (if (and (> (nrows-of self) 1 ) (<= (ncols-of self) 2 )) (loop for row in (row-format self) for s = (caar row) for s1 = (car (subviews-of s)) collect (if (typep s1 'point-symbol) (label-of s1) (identifier-name (viewed-object-of s1)))) (if (= 1 (nrows-of self)) (coord-strings (car (subviews-of self)))))) (defmethod margin-string-right ((self case-layout)) (if (and (> (nrows-of self) 1 ) (<= (ncols-of self) 2 )) (loop for row in (row-format self) for s = (caar (last row)) for s1 = (car (subviews-of s)) collect (if (typep s1 'point-symbol) (label-of s1) (identifier-name (viewed-object-of s1)))))) (defmethod margin-string-bottom ((self case-layout)) (if (and (> (ncols-of self) 1 ) (<= (nrows-of self) 2 )) (loop for col in (col-format self) for s = (caar col) for s1 = (car (subviews-of s)) collect (if (typep s1 'point-symbol) (label-of s1) (identifier-name (viewed-object-of s1)))) (if (= 1 (ncols-of self)) (coord-strings (car (subviews-of self)))))) (defmethod margin-string-top ((self case-layout)) (if (and (> (ncols-of self) 1 ) (<= (nrows-of self) 2 )) (loop for col in (col-format self) for s = (caar (last col)) for s1 = (car (subviews-of s)) collect (if (typep s1 'point-symbol) (label-of s1) (identifier-name (viewed-object-of s1)))))) (defmethod list-case-views ((self case-layout)) (loop for (s) in (layout-views-of self) collect (car (subviews-of s))))
6,940
Common Lisp
.l
149
33.416107
96
0.459913
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c4a9b3f5906dc87a9f884b87850b0664e7c60c8eb4c8b381bef28c201e495dab
33,258
[ -1 ]