On Wed, Apr 2, 2014 at 6:58 PM, Alexandre Bergel <alexandre.bergel@me.com> wrote:
Hi Usman,

Thanks for working on this very important problem. Legend are indeed important.
I would recommend, however, to have a builder for this. 

I started to work on a legend builder.  Here is an example:

-=—=-=-=—=-=-=—=-=-=—=-=-=—=-=-=—=-=
| v shape legendBuilder elements |
v := RTView new.

"We add some elements"
shape := RTShapeBuilder new circle
size: [ :c | 10 max: (c numberOfMethods) / 7 ];
fillColor: Color gray;
if: [ :cls | '*Array*' match: cls name ] fillColor: Color blue;
if: [ :cls | '*Dictionary*' match: cls name ] fillColor: Color green;
if: [ :cls | '*Set*' match: cls name ] fillColor: Color red;
current.
elements := shape elementsOn: (Collection withAllSubclasses).
elements @ RTPopup.
v addAll: elements.
RTGridLayout on: v elements.

"We add the legend"
legendBuilder := RTLegendBuilder new view: v.
legendBuilder name: 'array' color: Color blue.
legendBuilder name: 'dictionary' color: Color green.
legendBuilder name: 'set' color: Color red.
legendBuilder render.

"Open the view"
v open
-=—=-=-=—=-=-=—=-=-=—=-=-=—=-=-=—=-=

Result is the following:



Feel free to complete the builder. There is a lot to add more (e.g., spacing between the each item of the legend).
Does this make sense?

Yes. I agree, it is much better to work with the builders than working at the level of canvas. I had started to do at the level of TRCanvas because it provided services for fixed shapes and I wanted the legend to have a fixed position and it should be draggable. I think you have added support for fixed shapes at the level of the view so the builder should be work as desired.

tx for looking into it.
Usman
 

Cheers,
Alexandre


On Apr 2, 2014, at 9:14 AM, Usman Bhatti <usman.bhatti@gmail.com> wrote:

Hello,

I started to see how an implementation of a legend can be provided in Roassal 2.

I added this methods in TRCanvas>>addLegend:.. 


addLegend: aDictionary
| startPos interNodeWidth|
interNodeWidth := 30.
fixedShapes isEmpty ifTrue: [ startPos := self topLeft + (10@20) ] ifFalse: [startPos := self topLeft + (10@40)].
aDictionary associationsDo: 
[ :association |
|shape|
self
addFixedShape:
(TRBoxShape new
size: 10;
translateTo: startPos;
color: association value).
shape := (TRLabelShape new
text: association key;
fontSize: 10).
shape translateTo: (shape width /2) + startPos x + 10 @ startPos y.
self
addFixedShape: shape.
startPos := startPos x + shape width + interNodeWidth @ startPos y ].


Usage example:
============================================
| v e1 e2 l |
v := RTView new.
e1 := (RTEllipse new size: 30; color: (Color blue alpha: 0.3)) element.

e2 := (RTEllipse new size: 30; color: (Color yellow alpha: 0.3)) element.

l := (RTLine new attachPoint: RTShorterDistanceAttachPoint new) edgeFrom: e1 to: e2.
 
e1 @ RTDraggable.
e2 @ RTDraggable.

v canvas addLegend: ({ 'Red' -> Color red. 'very very green' -> Color green.'blue' -> Color blue. 'Cyan' -> Color cyan. 'Cyan2' -> Color cyan}) asDictionary.
v addAll: (Array with: l with: e2 with: e1).


v open

=========================================
Questions for Roassal guys:

- Is TRCanvas the right place to add a legend? I started from here because it allows adding fixed shapes to the view. 
- how do I tell the canvas not to draw where meta-items are drawn such as legend(s), menus, etc.

If this is correct, Leo might continue from here on and put this code in a class to add more customizations.

tx,
Usman
_______________________________________________
Moose-dev mailing list
Moose-dev@iam.unibe.ch
https://www.iam.unibe.ch/mailman/listinfo/moose-dev

-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




_______________________________________________
Moose-dev mailing list
Moose-dev@iam.unibe.ch
https://www.iam.unibe.ch/mailman/listinfo/moose-dev