invalid default drawing: #f
Hello, thefollowing code generates an « invalid default drawing » error in LispPad 2.1 on IPadOs 18.2:
import (lispkit draw chart bar))
(draw-bar-chart
(list (bar "Jan" 0) (bar "Feb" 2) (bar "Mar" 6) (bar "Apr" 9) (bar "May" 14) (bar "Jun" 16) (bar "Jul" 19) (bar "Aug" 18) (bar "Sep" 15) (bar "Oct" 11) (bar "Nov" 5) (bar "Dec" 2))
gray 5 "Temperature [C°]" "Month"
(point 50 105) (make-bar-chart-config 'size: (size 495 200))
(make-legend-config 'font: (font "Helvetica" 7) 'stroke-width: 0.4 'entry-pad: 5 'sample-area-width: 16 'sample-length: 8 'horizontal-offset: 50))
Functions whose name starts with draw- typically draw something into a drawing that is provided optionally as the last parameter. If the last parameter is missing (like in your example), the current drawing is used instead. It is implemented via the parameter object current-drawing of library (lispkit draw).
So you have two choices here: 1) provide a drawing parameter, or 2) make sure that current-drawing refers to a valid drawing (vs. #f — which is the default).
This is how approach 1 looks like:
(import (lispkit base) (lispkit draw) (lispkit draw chart bar))
(define d (make-drawing))
(draw-bar-chart
(list (bar "Jan" 0) (bar "Feb" 2) (bar "Mar" 6)
(bar "Apr" 9) (bar "May" 14) (bar "Jun" 16)
(bar "Jul" 19) (bar "Aug" 18) (bar "Sep" 15)
(bar "Oct" 11) (bar "Nov" 5) (bar "Dec" 2))
gray 5 "Temperature [C°]" "Month" (point 10 0)
(make-bar-chart-config 'size: (size 500 200))
#f d)
(save-drawing "test.pdf" d (size 520 210))
(open-file "test.pdf")
And here's the same example using the drawing syntax which creates a new empty drawing, assigns it to current-drawing and then invokes all the statements in the body of drawing:
(import (lispkit base) (lispkit draw) (lispkit draw chart bar))
(define d
(drawing
(draw-bar-chart
(list (bar "Jan" 0) (bar "Feb" 2) (bar "Mar" 6)
(bar "Apr" 9) (bar "May" 14) (bar "Jun" 16)
(bar "Jul" 19) (bar "Aug" 18) (bar "Sep" 15)
(bar "Oct" 11) (bar "Nov" 5) (bar "Dec" 2))
gray 5 "Temperature [C°]" "Month" (point 10 0)
(make-bar-chart-config 'size: (size 500 200))
#f)))
(save-drawing "test.pdf" d (size 520 210))
(open-file "test.pdf")
I hope this helps.
Many thanks Matthias.The example is very helpful.Perhaps you could include it in the documentation.Le 31 déc. 2024 06:18, Matthias Zenger @.***> a écrit : Functions whose name starts with draw- typically draw something into a drawing that is provided optionally as the last parameter. If the last parameter is missing (like in your example), the current drawing is used instead. It is implemented via the parameter object current-drawing of library (lispkit draw). So you have two choices here: 1) provide a drawing parameter, or 2) make sure that current-drawing refers to a valid drawing (vs. #f — which is the default). This is how approach 1 looks like: (import (lispkit base) (lispkit draw) (lispkit draw chart bar)) (define d (make-drawing)) (draw-bar-chart (list (bar "Jan" 0) (bar "Feb" 2) (bar "Mar" 6) (bar "Apr" 9) (bar "May" 14) (bar "Jun" 16) (bar "Jul" 19) (bar "Aug" 18) (bar "Sep" 15) (bar "Oct" 11) (bar "Nov" 5) (bar "Dec" 2)) gray 5 "Temperature [C°]" "Month" (point 10 0) (make-bar-chart-config 'size: (size 500 200)) #f d) (save-drawing "test.pdf" d (size 520 210)) (open-file "test.pdf") And here's the same example using the drawing syntax which creates a new empty drawing, assigns it to current-drawing and then invokes all the statements in the body of drawing: (import (lispkit base) (lispkit draw) (lispkit draw chart bar)) (define d (drawing (draw-bar-chart (list (bar "Jan" 0) (bar "Feb" 2) (bar "Mar" 6) (bar "Apr" 9) (bar "May" 14) (bar "Jun" 16) (bar "Jul" 19) (bar "Aug" 18) (bar "Sep" 15) (bar "Oct" 11) (bar "Nov" 5) (bar "Dec" 2)) gray 5 "Temperature [C°]" "Month" (point 10 0) (make-bar-chart-config 'size: (size 500 200)) #f))) (save-drawing "test.pdf" d (size 520 210)) (open-file "test.pdf") I hope this helps.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>