Code covered by the BSD License  

Highlights from
draggable

5.0

5.0 | 10 ratings Rate this file 151 Downloads (last 30 days) File Size: 11.41 KB File ID: #4179

draggable

by Francois Bouffard

 

20 Nov 2003 (Updated 20 Jan 2012)

Allows graphical objects to be dragged in a figure.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

This function enables a graphical object (be it a line, plot, patch, rectangle, text box, etc.) to be dragged inside an axis, with a very simple syntax ("draggable(h)"), following or not horizontal, vertical or diagonal constraints. Limits can be imposed on the object's movement.

Some figure properties are changed by the function, but previous properties are restored as soon as the drag is stopped. The behavior of the object can be reverted to its original, non-draggable state, by issuing "draggable(h,'off')".

Typical uses of this function would include non-standard GUI elements, such as markers that are moved on a figure or image. A function which is called when the object is moved can be provided as an optional argument, so that the movement triggers further actions.

See the provided file dragdemo.m for usage examples.

Acknowledgements
This submission has inspired the following:
roitool, DIGITIZE07
MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (11)
23 Dec 2003 Ohad Gal

Well done.
you might want to add an option for the following:
1. force a movement of the object, using an outside calling function.
2. enable the user to choose it's rendering mode
3. export (and update a given edit box) the DX and DY movement of the object

anyways, It's great. thanks you !

Ohad.

31 Aug 2004 Laszlo Balkay

It is a really great work with impressive options.

Congratulations!

20 Jun 2005 w L  
04 Feb 2006 Tom Nagel

I love it because it learns me a lot about mousebutton handling.
I tried to make a text object draggable: that doesn't work!

13 Jul 2007 Paul Premakumar

Very handy file!

02 Oct 2007 Chris Sarantos

Excellent, just what I was looking for!

23 Oct 2008 Nathan Tomlin

Wow, amazingly well done!

31 Mar 2009 Florian Jousset

Thanks!
I used it to move text, and it worked well after adapting your code to objects having a "Position" property of 3 values.

17 Aug 2009 Steven Bierer

An excellent, deviously simple tool. The code is well commented, and I was easily able to modify it to include a new input argument: a function handle that executes AFTER the object has been dragged. (I will contact the author with this addition, in case he'd like to incorporate it.)

12 Jan 2012 Brett Shoelson

Most excellent work...rock solid!

13 Jan 2012 Francois Bouffard

Sorry for the years-long delay since the last update... The Jan 13 update contains a bug fix by G. Fortin and Steven Bierer's drag-end function call. I'll try to add Brett's suggestion shortly.

Please login to add a comment or rating.
Updates
24 Nov 2003

Changed the category from "GUI tools and examples" to more accurate "Graphics: Graphical Data Exploration and Interaction".

15 Jan 2004

- Changed the category from "GUI tools and examples" to more accurate "Graphics: Graphical Data Exploration and Interaction".
- Now distributing .zip archive containing both draggable.m and a demo function, dragdemo.m.

19 Feb 2004

- Bugfix: now works with 1-element plot and line objects
- Added: polygon with draggable vertices in as demo 'polymove' in dragdemo

04 Mar 2004

- Bugfix: sanitized movement computation.
- The 'snapgrid' demo has been simplified.
- The 'polymove' demo has been polished.

05 Mar 2004

- Bugfix: yet another correction to movement computation. Now behaves correctly when mouse is out of axes.

01 Aug 2006

Bugfix for Matlab 7+: axes no longer disappear. Renderer option removed.

13 Jan 2012

implemented a feature and fixed a bug (both user-suggested)

20 Jan 2012

Major update. Now supports text objects. Diagonal constraints with arbitrary slopes added. Single call for applying draggable on multiple objects sharing the same parameters supported. Added the 'sliders' demo in dragdemo. General cleanup.

Tag Activity for this File
Tag Applied By Date/Time
data exploration Francois Bouffard 22 Oct 2008 07:09:47
drag Francois Bouffard 22 Oct 2008 07:09:47
object Francois Bouffard 22 Oct 2008 07:09:47
gui Francois Bouffard 22 Oct 2008 07:09:47
graphics Francois Bouffard 22 Oct 2008 07:09:47
draggable Francois Bouffard 22 Oct 2008 07:09:47
potw Lindsay Coutinho 13 Jan 2012 11:03:51
pick of the week Lindsay Coutinho 13 Jan 2012 11:03:51

Contact us at files@mathworks.com