das-developers / das2java

The original das2 library. Provides interactive publication-ready 2-D plotting
https://das2.org
GNU Lesser General Public License v3.0
4 stars 0 forks source link

DasAnnotation anchorType=plot, other annotation clean up #47

Open jbfaden opened 1 year ago

jbfaden commented 1 year ago

DasAnnotation has always had three modes to anchor (position) the annotation: canvas, plot, and data. I think the original idea was that "data" was going to allow anchoring to data, where the bounds of the data were going to be used to position the data. This never happened, and a simple bounding box (xrange = 20 to 25; yrange = 40 to 45) is allowed and Autoplot scripts are used to identify the data bounds. The "plot" mode was going to anchor to axes, but is never used because this is what the data position does. (Canvas just anchors to a row and column, or null values are just the entire canvas.) Further complicating things, we later added a verticalAnchorType which allows the two dimensions to be independently controlled.

I'd like for the "plot" to be made useful, where inside anchorPositions will clip using the plot clip, and outside anchorPositions will clip using reasonable boundaries so that adjacent plots are not affected. (Item 1)

There is additional cleanup which is needed, such as an improved GUI to control it, which Autoplot could use. (It has a quick one I threw together, but I don't think it's very effective.) (Item 2)

One still cannot rotate annotations, and this is an obvious feature that is overdue (Item 3). The properties "url" and "scale" should be deprecated since painters can be used for images (Item 4). "<img>" tags were supposed to be supported as well, but that's a different ticket (Item 5).

Last, there needs to be a clean document describing annotation use (Item 6).

See https://github.com/das-developers/das2java/issues/21, and Autoplot ticket https://sourceforge.net/p/autoplot/bugs/1696/ .

jbfaden commented 1 year ago

Also I'd like for there to be a way to specify how tight the margins are around the text. It looks like it's roughtly 1em right now, but sometimes I'd like to have no margin at all.

jbfaden commented 1 year ago

Also there should be a border type where it is just an underline, which can be used for pointing.

image

jbfaden commented 1 year ago

The bounds of a plot or data anchored annotation are not clipped properly, and slightly overlap the plot bounds.

image

jbfaden commented 1 year ago

See also https://github.com/autoplot/dev/blob/master/bugs/2023/20230210/demoAnnotations.jy

jbfaden commented 1 year ago

(Item 7) The "point at" mouse module included within the annotations would adjust the anchorOffsets, incorrectly. The pointAt point is different that the xrange and yrange which position the annotation, and the two should not be coupled.

jbfaden commented 1 year ago

(Item 8) "move annotation" adjusts anchorOffsets, but does not consider splitAnchorType.

jbfaden commented 1 year ago

(Item 9) "move annotation" has a sign error in Y when anchorPosition is OutsideNE. All branches of adjustAnchorOffset should be reviewed.

This script is useful:

from org.das2.graph import AnchorPosition

i=0
for v in AnchorPosition.values():
    annotation( i, anchorPosition=v, text=str(v) )
    i=i+1
jbfaden commented 1 year ago

Item 8 was not a bug. There is no special consideration needed.

jbfaden commented 1 year ago

I realized there is no way to attach an annotation to the data and have it draw outside the plot, like so:

image

I experimented with this and it seems like we'll need another control. anchorType "data" and "plot" both clip.

jbfaden commented 10 months ago

(7 and 12) I've always found the DATA mode for positioning strange, and I think I've finally figured out why. When "showArrow" was on, it would use the pointAt position to locate, and the xrange,yrange box otherwise. I'm correcting this, but I'm this will likely break existing products. It's always a good idea to favor the simpler code, and this is the simpler solution (and it removes about 12 lines of code).

jbfaden commented 9 months ago

I found that with splitAnchor type and verticalAnchorType=CANVAS, the anchor would still be clipped. This is fixed.

jbfaden commented 9 months ago

https://github.com/das-developers/das2java/issues/92 where GrannyTextRenderer doesn't clip painters properly.