gujjula / core-plot

Automatically exported from code.google.com/p/core-plot
0 stars 0 forks source link

Area Selection Rect #259

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Many Mac apps use an area selection rectangle, sometimes with marching ants, to 
select a region of a plot for zooming and other applications. It would be good 
if it were possible to 'turn on' and position a selection rect layer inside a 
graph. It would only exist within the bounds of the plot area, and could be 
positioned in either plot area view coordinates, or in plotting coordinates. 

If a bordered layer was used, the selection rect could be styled with custom 
fills, line styles, and rounded corners etc.

The selection rect should be usable programmatically, independent of a mouse or 
mouse dragging events. It should be entirely usable with a method call API.

Independently, options could be added to the host view on the Mac to allow 
mouse events to trigger the selection rect, and then zoom to the selection. But 
the selection rect should be available for other purposes than zooming (eg 
selection of points), and should be accessible whether you are using mouse 
events or not.

Original issue reported on code.google.com by drewmcco...@mac.com on 18 Feb 2011 at 3:34

GoogleCodeExporter commented 9 years ago
You could possibly just make a CPBorderedLayer subclass called 
CPSelectionLayer, and expose that layer via a property in the graph. That class 
would have methods for positioning it in the plot space, and hiding it etc. 

The layer would then be added on top of all other layers when it is visible.

Original comment by drewmcco...@mac.com on 18 Feb 2011 at 3:46

GoogleCodeExporter commented 9 years ago
This sounds like a specialized CPAnnotation. It just needs to handle the mouse 
interaction to make it appear, disappear, and resize.

Original comment by eskr...@mac.com on 19 Feb 2011 at 1:45

GoogleCodeExporter commented 9 years ago
There are similarities, but I think it would be better to have a separate 
entity called a selection rect. For example, people might want to customize its 
appearance, perhaps putting little arrows or crosshairs in it, or something 
like that.

The other thing is that it defines an area of the plot space, which a 
CPPlotSpaceAnnotation is anchored to a single point. So there are some 
fundamental differences, and it would probably be cleaner to make a custom 
class to handle those differences.

Original comment by drewmcco...@mac.com on 19 Feb 2011 at 4:03

GoogleCodeExporter commented 9 years ago
I have a solution to draw an area selection rectangle.
I wrote a class "AreaSelectionRectangle" which draws a dashed rectangle with 
Quartz, it only draws it, it's up to you on how to use it (for example to 
select an area, or to zoom inside this area).

You just need to add the class to your Controller and set it as as subViews to 
your CPLayerHostingView hostView

Then you need to put your CPXYGraph *graph to zPosition = -1
I've tried it on the example DatePlot and it works (but remember it just draws 
a dashed rectangle and doesn't select any point yet).

Please try it (see attachment and let me know if code is good or crappy :-)

        // --------------------------------------------------------------------------------
    // Begin: code to add an area selection rectangle
    // ----------------------------------------------------------------------------
    myAreaSelection = [[AreaSelectionRectangle alloc] initWithFrame:[hostView bounds]];
    NSArray *areaSelections = [[NSArray alloc] initWithObjects:myAreaSelection,nil];

    // Add the areaSelections as a subView
    // The same can be done in "Interface Builder" by putting
    [hostView setSubviews:areaSelections];
    [areaSelections release];   

    // Put the graph at zPosition -1 to display the areaSelection
    graph.zPosition = -1;

    // ------------------------------------------------------------------------------
    // End: code to add an area selection rectangle
    // ------------------------------------------------------------------------------

Original comment by celgil...@gmail.com on 25 Feb 2011 at 11:33

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The above code to put "myAreaSelection" as a "subView" for the "hostView" works 
OK when "hostView" is not resized.
Since "myAreaSelection" is not set to autoresize I suggest doing it in 
Interface Builder

It's better to put the AreaSelectionRectangle (NSView subclass) in Interface 
Builder as a subview of "hostView"
and enable "Autosizing".

If you have a background (CPBorderedLayer) you must set its zPoisition to -2 
and the CPXYGraph graph zPosition to -1.

Also in the above code we don't need an NSArray to put as a subView. We just 
can use method addSubview:

hope this helps

Original comment by celgil...@gmail.com on 25 Feb 2011 at 5:13

GoogleCodeExporter commented 9 years ago
Moved to GitHub issue #10.

https://github.com/core-plot/core-plot/issues/10

Original comment by eskr...@mac.com on 29 Dec 2013 at 1:40