-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose converting between plot/view/context coordinates #83
Comments
Given how
A metrics objects might be a struct or object along the lines of:
Using axis transforms instead of invertible-functions directly might be more appropriate? You could also expose the internal |
The main challenge with this request (and #7 as well) is designing the new API -- unfortunately, the design of the plot package does not make this easy, since there are many entry points to creating plots, and all of them need to support all the features (if it makes sense for them, of course). Returning a metrics object would work for
In addition to that, there are some special I think the main And, of course, it would also be nice if the API change would be made in such a way that the 3D variants of these functions could also be updated to provide similar functionality. |
Would it make sense if there were a new function that accepted only a plot and returned information about how drawing coordinates mapped into plotted coordinates? Then, if there were functions that took a plot and returned a pict, or a bitmap, or a snip, you could refactor plot-pict to be the composition of a function that produces a plot with the function that turns a plot into a pict? |
Well, all the non-GUI plot functions, such as We could just leave On a slightly separate note, @dented42 , could you describe what are you trying to achieve overall (e.g. the application that you are trying to build), perhaps there is a solution that could be implemented with existing plot functionality... |
Oh, I see. Probably best to not change the What about a combination that was a new keyword argument that, if supplied, caused each of these functions to return two values (whatever it returned before and also the metrics)? As for code duplication, I guess the headers get long and are duplicated but perhaps this could be done with a macro? (Or maybe it is already?) |
If we add a keyword argument, my preference would be to make it an optional "output parameter" using a box, like so: (let ([metrics-boxed (box #f)])
(define pict (plot-pict ... #:metrics metrics-boxed))
(define metrics (unbox metrics))
;; use metrics here
) A similar technique is already used by the |
get-extent does that because it was ported from C code. The extra box feels
clunky in Racket (at least to me) -- it requires an extra step compared to
just accepting multiple values as a result.
Robby
…On Wed, Feb 17, 2021 at 11:42 PM Alex Harsányi ***@***.***> wrote:
If we add a keyword argument, my preference would be to make it an
optional "output parameter" using a box, like so:
(let ([metrics-boxed (box #f)])
(define pict (plot-pict ... #:metrics metrics-boxed))
(define metrics (unbox metrics))
;; use metrics here
)
A similar technique is already used by the snip% get-extent method...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#83 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADBNMAWNP3Y3XU6MB2IRGTS7SSEDANCNFSM4XZFVICA>
.
|
The extra box is not great, but it seems better than an API that changes how many values it returns based on a keyword argument. That would be an awkward API to encode in Typed Racket, which is both relevant for plot and (in my opinion) a sign of an API that's awkward to use as well. |
I came to the same conclusion as Sam yesterday as I saw the first post about a "variable result" signature. But I took one extra step: the "forced" use of a box in this situation suggests a weakness in the type system. When I faced a similar problem with |
I think the goal was to avoid adding another function, but maybe that's the right thing given the type system issues. That is, a new function that returns the same procedure that |
I am not proposing a new function. I am proposing f : A x [#:metric B] -> void u metric where we "know" that metric shows up only when an optional argument of type B is supplied. |
Oh! I see. That's better. I misunderstood. |
Hi @mfelleisen , Unfortunately I am not familiar with this notation:
Thanks, |
Sorry, I should have used Typed Racket notation:
```
(: f (-> Integer [#:metrics String] (U Boolean Void)))
(define (f {x : Integer} #:metrics [m : String "default"]) : (U Void Boolean)
(if (equal? m "default")
(void)
#false))
```
The `(U Void Boolean)` means `f` returns either `Void` or `Boolean`.
In your case, you’d return `Void` or the metrics coordinate info.
|
I've just been trying to build some toy interactive examples of various kinds of discrete Fourier transforms, but metrics seems like a useful thing outside of that. I've been using |
Hi @dented42 , You can already build these interactive Fourier transforms using plot snips and the GUI library. It is just that you cannot implement them using the If you want to keep using https://github.com/racket/plot/blob/master/plot-test/plot/tests/PRs/snip-empty-selection.rkt |
@alex-hhh Interesting I'll look at that. My understanding though, is that plot snip overlays can only be used to add additional things to the underlying plot and can't be used for changing/altering things that are already plotted? |
@dented42 , your understanding is correct, however you can have the underlying plot contain a single transparent point (or perhaps a point outside the plot range), and all the other things would be plotted using |
For the original question:
Then plot/dc could return an for gist trying this out: plot/private/no-gui/plot2d.rkt
|
Hi @bdeket , I like your proposal, and I think it would work. I don't think we would need to change @rfindler you had some concerns about changing the return type of Also, does anyone else see a problem with |
Hi @dented42 , @bdeket has implemented what you requested as part of the #90 pull request. Could you try these changes and see if they are sufficient for what you wanted to do with the plot package and lux? This is the branch that contains the changes: https://github.com/bdeket/plot/tree/plotmetrics |
I agree that a function that used to return void now returning something useful isn't the end of the world. It is backwards incompatible but it seems unlikely to be relied on. But if it were to be relied on, it'd be something like someone who wrote a function with a contract where that function's contract says it returns void, but it really returns whatever the plot function returns (because it just happens to call that function last). This would end up with that person's function getting blame where it used to work fine. The types might be more of a problem, tho. (Not sure if this library has a typed version.) (I got email with a comment that I'm replying to now but I don't see that comment. Not sure if that's because I'm doing this wrong or what.) |
The `Plot-Metrics<%>` interface implements functions to query information about the plot. Currently, `get-plot-bounds`, `plot->dc` and `dc->plot` methods are implemented. Objects returned by plot/dc, `plot-bitmap` and `plot-snip` implement this interface in addition to their respective types (e.g. a `bitmap%` for `plot-bitmap` and `snip%` for `plot-snip`). `plot-pict` returns a `pict` which is extended with these new interface functions as well.
Late to the party again, alas. But I should chip in to say that the proposed/discussed/accepted solution covers my needs quite elegantly. |
Pull request #90 implements the plot-metrics interface, a mechanism that allows the user to determine the location of elements on the plot image itself, so plots can be further decorated, it is based on a request in issue #83. While this functionality has been available for a while now, it was not documented. This PR adds documentation to this interface, so users can discover the functionality and use it.
I'm trying to integrate plot into a larger program and need a way to take coordinates in the drawing context (I'm using
plot/dc
) and convert them to coordinates in the plot (and back again).I'm aware of the word done with
set-mouse-event-callback
etc. but I don't think using snips makes sense for my program (I'm usinglux
, which just gives me a drawing context).The text was updated successfully, but these errors were encountered: