Commit 49a0f93d authored by Ryan Davis's avatar Ryan Davis

added GChart support for the draw-zero-p axis option. This adds zero...

added GChart support for the draw-zero-p axis option.  This adds zero explicitly to the data when processing min and max values.

darcs-hash:20090413153954-ac9f3-b5ce12bfe0759fe9724f701c323f7f6d6d978bc0.gz
parent 7709685a
......@@ -207,10 +207,19 @@ a function of 1 argument to control label formatting"
(:y (setf (y-axis *current-chart*) ax)))))
(defun find-chart-extremes (chart)
(find-extremes
(mapcan #'(lambda (series)
(find-extremes (data series)))
(chart-elements chart))))
(let ((data-minmax (find-extremes
(mapcan #'(lambda (series)
(find-extremes (data series)))
(chart-elements chart))))
(x-zero (draw-zero-p (x-axis chart)))
(y-zero (draw-zero-p (y-axis chart))))
(if (or x-zero y-zero)
(destructuring-bind ((min-x min-y) (max-x max-y)) data-minmax
(declare (ignore max-x max-y))
(when x-zero (push (list 0 min-y) data-minmax))
(when y-zero (push (list min-x 0) data-minmax))
(find-extremes data-minmax))
data-minmax)))
(defun find-extremes (data)
"takes a list of (x y) pairs, and returns the ((x-min y-min) (x-max y-max))"
......
......@@ -27,6 +27,16 @@
(parameters :accessor parameters
:initform (make-parameter-collection)
:initarg :parameters)
(x-axis :accessor x-axis
:initarg :x-axis
:initform nil
:documentation "an axis object to determine formatting for
the X axis")
(y-axis :accessor y-axis
:initarg :y-axis
:initform nil
:documentation "and axis object to determine formatting for
the Y axis")
(axes :accessor axes
:initform (make-hash-table))))
......@@ -243,13 +253,13 @@
(param (if (eql :auto (data-interval axis))
:chxr :chxl)))
(setf (gethash idx (axes chart)) axis)
(append-parameter param (list idx valfn (label-formatter axis)))))
(append-parameter param (list idx valfn (label-formatter axis) (draw-zero-p axis)))))
(defmethod (setf x-axis) (ax (chart gchart))
(defmethod (setf x-axis) :before (ax (chart gchart))
(add-axis "x" #'x ax chart))
(defmethod (setf y-axis) (ax (chart gchart))
(add-axis "y" #'y ax chart))
(defmethod (setf y-axis) :before (ax (chart gchart))
(add-axis "y" #'y ax chart))
(defun add-features (&rest names)
(mapc #'add-feature names))
......@@ -273,28 +283,37 @@
(defmethod finalize-parameter ((key (eql :chxl)) val)
(format nil "~{~a~^|~}"
(loop for (idx valfn formatfn) in val
(loop for (idx valfn formatfn draw-zero-p) in val
collect (format nil "~D:|~{~a~^|~}" idx
(mapcar formatfn
(sort
(remove-duplicates
(loop for elem in (chart-elements *current-chart*)
nconc (mapcar valfn (data elem))))
(let ((vals (loop for elem in (chart-elements *current-chart*)
nconc (mapcar valfn (data elem)))))
;;if we want to draw 0, add it to the list
(when draw-zero-p (push 0 vals))
vals))
#'<))))))
(defmethod finalize-parameter ((key (eql :chxr)) val)
(let ((all-data (mapcan #'data (chart-elements *current-chart*))))
(format nil "~{~a~^|~}"
(loop for (idx valfn formatfn) in val
collect (format nil "~D,~{~,2F~^,~}" idx
;;find the function for scaling this axis, scale
(mapcar (or (scalefn (gethash idx (axes *current-chart*)))
#'identity)
;;find the global min/max
(loop for x in (mapcar valfn all-data)
minimizing x into min
maximizing x into max
finally (return (list min max)))))))))
(loop for (idx valfn formatfn draw-zero-p) in val
collect (format nil "~D,~{~,2F~^,~}" idx
(let ((vals (mapcar valfn all-data)))
;;add zero if we want to
(when draw-zero-p (push 0 vals))
;;find the global min/max
(let ((minmax (loop for x in vals
minimizing x into min
maximizing x into max
finally (return (list min max)))))
;;find the function for scaling this axis, scale
(if-let (scalefn (scalefn (gethash idx (axes *current-chart*))))
(mapcar scalefn minmax)
minmax))))))))
(defmethod build-parameters ((chart gchart))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment