Fixed aspect ratio for ZoomTool

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Fixed aspect ratio for ZoomTool

Brennan Sellner
Hi all,

I have a simple Chaco plot that I'm using to visualize the motion of an
object in the world by plotting its XY location over time.  I've set up
the plot so that the scale:pixel ratio is the same for both index and
value, in order to avoid deforming the plot.  By setting stretch_data in
the appropriate places, this is maintained as the plot/window is resized.

My problem comes when zooming.  I have both the ZoomTool (a.k.a
BetterSelectingZoom) and DragZoom installed.  DragZoom isn't a problem,
since its maintain_aspect_ratio trait does the trick.  Using the mouse
wheel with ZoomTool likewise does the right thing.

However, I'm stuck when it comes to zooming with a box drag via
ZoomTool: I can't figure out how to specify a fixed aspect ratio for the
zoom box.  Is it possible?  In the spirit of flailing wildly, I tried
setting the aspect_ratio trait on ZoomTool, but it had no effect (which
isn't much of a surprise, given the comments in enable.component).

I'd appreciate any hints!

My apologies if this should be on chaco-users, but it's pretty dead over
there...

Thanks,

-Brennan

----------
My apologies for the following disclaimer; it's added unconditionally by
our mail gateway.
Email Confidentiality Notice

The information contained in this transmission is confidential, proprietary or privileged and may be subject to protection under the law. This message is intended for the sole use of the individual or entity to whom it's addressed. If you are not the intended recipient, you are notified that any use, distribution or copying of the message is strictly prohibited and may subject you to criminal or civil penalties. If you received this transmission in error, please contact the sender immediately by replying to this email and delete the material from any computer.
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fixed aspect ratio for ZoomTool

Peter Wang-2
Hey Brennan,

I just saw this now.  This was not currently supported, but I just submitted a pull request that adds handling of the aspect_ratio trait to the ZoomTool.


-Peter


On Sun, Jan 27, 2013 at 5:17 PM, Brennan Sellner <[hidden email]> wrote:
Hi all,

I have a simple Chaco plot that I'm using to visualize the motion of an
object in the world by plotting its XY location over time.  I've set up
the plot so that the scale:pixel ratio is the same for both index and
value, in order to avoid deforming the plot.  By setting stretch_data in
the appropriate places, this is maintained as the plot/window is resized.

My problem comes when zooming.  I have both the ZoomTool (a.k.a
BetterSelectingZoom) and DragZoom installed.  DragZoom isn't a problem,
since its maintain_aspect_ratio trait does the trick.  Using the mouse
wheel with ZoomTool likewise does the right thing.

However, I'm stuck when it comes to zooming with a box drag via
ZoomTool: I can't figure out how to specify a fixed aspect ratio for the
zoom box.  Is it possible?  In the spirit of flailing wildly, I tried
setting the aspect_ratio trait on ZoomTool, but it had no effect (which
isn't much of a surprise, given the comments in enable.component).

I'd appreciate any hints!

My apologies if this should be on chaco-users, but it's pretty dead over
there...

Thanks,

-Brennan

----------
My apologies for the following disclaimer; it's added unconditionally by
our mail gateway.
Email Confidentiality Notice

The information contained in this transmission is confidential, proprietary or privileged and may be subject to protection under the law. This message is intended for the sole use of the individual or entity to whom it's addressed. If you are not the intended recipient, you are notified that any use, distribution or copying of the message is strictly prohibited and may subject you to criminal or civil penalties. If you received this transmission in error, please contact the sender immediately by replying to this email and delete the material from any computer.
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fixed aspect ratio for ZoomTool

Brennan Sellner
Thanks, Peter!

For now, I've subclassed BetterSelectingZoom to patch in your new
selecting_mouse_move.  It's working quite well.

For those who may come across this in the future, I did add one hack to
the very beginning of selecting_mouse_move: since the aspect ratio may
change when the window is resized, I recompute it there, and use the
user-set self.aspect_ratio as a flag.  This should probably be
elsewhere, but I couldn't figure out where to set up a listener/signal
handler/subscription to component resize events.

Patch, inserted in the very beginning of selecting_mouse_move:

    # This is a HACK: if the aspect ratio is not None, update it
    # to match the current aspect ratio of our component.  This
    # should really go somewhere else (the component?), and be
    # controlled by a separate flag.
    if self.aspect_ratio is not None:
        comp = self.component
        cWidth = comp.x_mapper.high_pos - comp.x_mapper.low_pos
        cHeight = comp.y_mapper.high_pos - comp.y_mapper.low_pos
        if cWidth != 0 and cHeight != 0:
            self.aspect_ratio = cWidth / cHeight

Thanks again!

-Brennan

On 02/07/2013 12:25 AM, Peter Wang wrote:

> Hey Brennan,
>
> I just saw this now.  This was not currently supported, but I just
> submitted a pull request that adds handling of the aspect_ratio trait to
> the ZoomTool.
>
> https://github.com/enthought/chaco/pull/90
>
> -Peter
>
>
> On Sun, Jan 27, 2013 at 5:17 PM, Brennan Sellner <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hi all,
>
>     I have a simple Chaco plot that I'm using to visualize the motion of an
>     object in the world by plotting its XY location over time.  I've set up
>     the plot so that the scale:pixel ratio is the same for both index and
>     value, in order to avoid deforming the plot.  By setting stretch_data in
>     the appropriate places, this is maintained as the plot/window is
>     resized.
>
>     My problem comes when zooming.  I have both the ZoomTool (a.k.a
>     BetterSelectingZoom) and DragZoom installed.  DragZoom isn't a problem,
>     since its maintain_aspect_ratio trait does the trick.  Using the mouse
>     wheel with ZoomTool likewise does the right thing.
>
>     However, I'm stuck when it comes to zooming with a box drag via
>     ZoomTool: I can't figure out how to specify a fixed aspect ratio for the
>     zoom box.  Is it possible?  In the spirit of flailing wildly, I tried
>     setting the aspect_ratio trait on ZoomTool, but it had no effect (which
>     isn't much of a surprise, given the comments in enable.component).
>
>     I'd appreciate any hints!
>
>     My apologies if this should be on chaco-users, but it's pretty dead over
>     there...
>
>     Thanks,
>
>     -Brennan
>
>     ----------
>     My apologies for the following disclaimer; it's added unconditionally by
>     our mail gateway.
>     Email Confidentiality Notice
>
>     The information contained in this transmission is confidential,
>     proprietary or privileged and may be subject to protection under the
>     law. This message is intended for the sole use of the individual or
>     entity to whom it's addressed. If you are not the intended
>     recipient, you are notified that any use, distribution or copying of
>     the message is strictly prohibited and may subject you to criminal
>     or civil penalties. If you received this transmission in error,
>     please contact the sender immediately by replying to this email and
>     delete the material from any computer.
>     _______________________________________________
>     Enthought-Dev mailing list
>     [hidden email]
>     <mailto:[hidden email]>
>     https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>

Email Confidentiality Notice

The information contained in this transmission is confidential, proprietary or privileged and may be subject to protection under the law. This message is intended for the sole use of the individual or entity to whom it's addressed. If you are not the intended recipient, you are notified that any use, distribution or copying of the message is strictly prohibited and may subject you to criminal or civil penalties. If you received this transmission in error, please contact the sender immediately by replying to this email and delete the material from any computer.
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fixed aspect ratio for ZoomTool

Peter Wang-2
On Fri, Feb 15, 2013 at 12:54 PM, Brennan Sellner <[hidden email]> wrote:
user-set self.aspect_ratio as a flag.  This should probably be
elsewhere, but I couldn't figure out where to set up a listener/signal
handler/subscription to component resize events.

You should listen to component.bounds_changed and .bounds_items_changed.

-Peter

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev