plot-container – Embed plot snips to GUI applications
1 plot-container% Class
(require plot-container) | package: plot-container |
|
superclass: editor-canvas% |
constructor
(new plot-container% [parent parent] [ [columns columns] [spacing spacing]]) → (is-a?/c plot-container%)
parent :
(or/c (is-a?/c frame%) (is-a?/c dialog%) (is-a?/c panel%) (is-a?/c pane%)) columns : positive-integer? = 1 spacing : positive-integer? = 5 Create a new instance of a plot-container% which will arrange plot snip% objects in columns columns with spacing pixels between them. The number of rows will be determined by the number of plot snips added. Additional init argyments can be passed in, they will all go to the editor-canvas% class, see its documentation for what options are available.
method
(send a-plot-container cell-dimensions snip-count)
→
real? real? snip-count : positive-integer? Return the dimensions of a plot snip when this plot-container% would hold snip-count snips. The dimensions will be calculated based on the current size of the canvas plus the number of columns and spacing between snips.This method can be used to construct the plot snip instances with the correct dimensions and avoid a snip resize operation when these snips are added to the container.
WARNING The cell dimensions are only valid if the snips are arranged in rows and columns by calling add-snips. If a layout is used, as per add-snips/layout, the cell dimensions returned by this method will not correspond to the ones assigned to the snips in the layout.
Clear all snips from the container.Set snip as the only snip managed by the container, replacing any previous plot snips.Set the contents of the container to the snip instances passed in as paramters, replacing any previous plot snips.
method
(send a-plot-container set-snips/layout group) → any/c
group : plot-container-group? Set the contents of the container to the group, which is a group of snips created using hgroup, vgroup and cgroup. This method allows subdividing the contents of the container area in a tree-like fashion.
method
(send a-plot-container add-floating-snip snip x y) → any/c snip : (is-a?/c snip%) x : real? y : real? Add snip as a floating snip to the container and place it at x, y. Any previous floating snips will be kept as well.
method
(send a-plot-container set-floating-snip snip x y) → any/c snip : (is-a?/c snip%) x : real? y : real? Remove all existing floating snips, than add snip as a floating snip to the container and place it at x, y.
method
(send a-plot-container set-background-message message) → any/c
message : (or/c #f string?) Set a message to be displayed in the plot container when it contains no snips at all. If the message is #f, no message will be displayed.
method
(send a-plot-container set-hover-pict pict x y) → any/c pict : (or/c #f pict?) x : real? y : real? Set pict to be displayed at locations x, y, or hide the pict when #f. The pict will be displayed on top of all other snips in the container and can be used to implement tool tips for the contents of the container.
method
(send a-plot-container set-hover-pict-at-mouse-event pict event) → any/c pict : (or/c #f pict?) event : (is-a?/c mouse-event%) Display pict at the location of the mouse event. This method will take the mouse event coordinates, convert them to plot container coordinates and call set-hover-pict.
procedure
(plot-container-group? group) → boolean?
group : any/c
procedure
(vgroup item ... [ #:border border #:spacing spacing]) → plot-container-group? item : (listof (or/c plot-container-group? (is-a?/c snip%))) border : (or/c positive? zero?) = 0 spacing : (or/c positive? zero?) = 5
procedure
(hgroup item ... [ #:border border #:spacing spacing]) → plot-container-group? item : (listof (or/c plot-container-group? (is-a?/c snip%))) border : (or/c positive? zero?) = 0 spacing : (or/c positive? zero?) = 5
procedure
(cgroup columns item ... [ #:border border #:spacing spacing]) → plot-container-group? columns : positive-integer? item : (listof (or/c plot-container-group? (is-a?/c snip%))) border : (or/c positive? zero?) = 0 spacing : (or/c positive? zero?) = 5
vgroup will place items in one vertical column with the height equally divided between all items.
hgroup will place items in one horizontal row with the width equally divided between all items.
cgroup will place all items in columns, with the number of rows depending on the number of itmes. The width is divided equally between the number of columns and the height is divided equally between the number of rows.
2 Some utility functions to use with plots and plot containers
(require plot-container/hover-util) | |
package: plot-container |
This module provides a collection of helper functions for building interactive plots. The plot-snip function returns a snip% representing the plot, and this snip has two additional methods, set-mouse-event-callback and set-overlay-renderers, which help with this. See the plot documentation for 2d-plot-snip% for more details.
procedure
(good-hover? snip x y event) → boolean?
snip : (is-a?/c snip%) x : (or/c real? #f) y : (or/c real? #f) event : (is-a?/c mouse-event%)
The parameters are considered valid when the coordinates x and y are not #f, the mouse event is a motion event and the plot snip is directly under the mouse with no other snips above it.
The x, y coordinates can be #f when they are inside the plot snip but not on the plot itself, for example in the axes area.
This function encapsulates all the logic on whether to add or clear overlay renderers from a plot, and allows writing hover callbacks in the following form:
(define (hover-callback snip event x y) (if (good-hover? snip x y event) ; Need to add overlay renderers for position x,y (send snip set-overlay-renderers ...) ; Nedd to clear any overlay renderers (send snip set-overlay-renderers #f)))
procedure
(xposition->histogram-slot xposition [ skip gap])
→
(or/c #f exact-nonnegative-integer?) (or/c #f exact-nonnegative-integer?) xposition : number? skip : number? = (discrete-histogram-skip) gap : number? = (discrete-histogram-gap)
Returns two values, the series, when multiple historams are plotted and the slot within that histogram. Will return (values #f #f) if the X position is between the bars of the histogram.
procedure
(get-snip-location snip) → (or/c #f (cons/c number? number?))
snip : (or/c #f (is-a?/c snip%))
Together with move-snip-to, this function can be used to retrieve and save the location of any hover snips in a plot-container% and restore them at a later time.
procedure
(move-snip-to snip location) → any/c
snip : (is-a?/c snip%) location : (or/c #f (cons/c number? number?))
Assumes the snip is added to an editor.