cl defpackage vecto-chart use cl vecto flexi-streams export render-png

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(cl:defpackage :vecto-chart
(:use :cl :vecto :flexi-streams)
(:export #:render-png-stream #:add-data #:with-line-chart #:draw-axis))
(in-package :vecto-chart)
(defclass chart ()
((width :accessor chart-width :initarg :width :initform 400)
(height :accessor chart-height :initarg :height :initform 300)
(data :accessor chart-data :initarg :data :initform nil)
(offset :accessor chart-offset :initarg :offset :initform 0)))
(defclass line-chart (chart)
((have-x-y :accessor chart-have-x-y :initform nil)
(min-x :accessor chart-data-min-x :initform 0)
(min-y :accessor chart-data-min-y :initform 0)
(max-x :accessor chart-data-max-x :initform 0)
(max-y :accessor chart-data-max-y :initform 0)
(ratio-x :accessor chart-ratio-x :initform 1)
(ratio-y :accessor chart-ratio-y :initform 1)))
(defclass pie-chart (chart)
())
(defmacro with-pie-chart ((&key width height) &body body)
`(let ((*current-chart* (make-instance 'pie-chart
:width ,width
:height ,height)))
(with-canvas (:width ,width :height ,height)
,@body)))
(defvar *current-chart* nil)
(defmacro with-line-chart ((&key width height) &body body)
`(let ((*current-chart* (make-instance 'line-chart
:width ,width
:height ,height
:offset (* ,height 0.05))))
(with-canvas (:width ,width :height ,height)
,@body)))