Created
February 6, 2018 10:23
-
-
Save alex-hhh/2394d60e57953f82e363fc68fae877b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
;; Updated plot library required, https://github.com/alex-hhh/plot/tree/ah/interactive-overlays | |
(require plot pict) | |
;; Helper function to add a pict as a plot overlay -- don't want to add "pict" | |
;; as a dependency to the "plot" package | |
(define (add-pict-overlay plot-snip x y pict) | |
(send plot-snip add-general-overlay x y | |
(lambda (dc x y) (draw-pict pict dc x y)) | |
(pict-width pict) | |
(pict-height pict))) | |
;; Will be called when the mouse moves over the plot SNIP. X and Y are the | |
;; mouse position in plot coordinates and they will be #f if the cursor is | |
;; outside of the actual plot area | |
(define (on-hover snip event x y) | |
(when (and x y) | |
;; ... but only if we are still inside the plot area | |
(define sx (sin x)) ; the function value at X | |
(send snip set-overlay-renderers (list (vrule x) (hrule sx))) | |
(send snip refresh-overlays))) | |
;; Create the plot snip and add the hover callback | |
(define snip (plot-snip (function sin) #:x-min -10 #:x-max 10)) | |
(send snip set-mouse-callback on-hover) | |
snip |
I think I know what is happening, I'll fix this sometimes next week.
I tried to fix this, but no success yet. Happy to talk more.
I figured it out, the problem was that the plot functions set their own clipping region and have to be passed the correct plot bounds and dc areas. I updated the draw function to use the region received by the snip draw method, see racket/plot#37 for more details. This was not a problem for the original implementation, because I did not change the clipping region in that case.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know much about drawing contexts either, but yes I will try working on this