Book a Demo

Author Topic: Setting Location of DiagramLink Labels to X/Y Coordinates  (Read 7069 times)

Rich Anderson

  • EA User
  • **
  • Posts: 142
  • Karma: +8/-0
    • View Profile
    • LinkedIn
Setting Location of DiagramLink Labels to X/Y Coordinates
« on: March 13, 2019, 02:01:33 pm »
Does anyone here know if it is possible to set the location of a DiagramLink label programatically?  I've looked around the documentation and the DiagramLinks class in the help system and I cannot find the methods or properties to set this.   What I want to do is create a TreeStyle Vertical link between two elements and place the label near one of the  DiagramElements using X/Y coordinates.  I can move it there manually with the GUI, but I'm generating a large number of diagrams where I need this set programatically.
Rich Anderson
Urgnt Limited

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Setting Location of DiagramLink Labels to X/Y Coordinates
« Reply #1 on: March 13, 2019, 06:07:42 pm »
Please help me out: what is a DiagramLink label?

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Setting Location of DiagramLink Labels to X/Y Coordinates
« Reply #2 on: March 13, 2019, 06:21:21 pm »
Location is in the database, so yes it is possible.

It might not be exposed in the API though, I'm not sure. In that case you'll have to update the database directly (using Repository.Execute())
I'm pretty sure it's not trivial. I played with connector positions on diagrams in the past, and I remember it was pretty hard to get my head around it. I can imagine that this will be the same for the label positions.

Geert

Rich Anderson

  • EA User
  • **
  • Posts: 142
  • Karma: +8/-0
    • View Profile
    • LinkedIn
Re: Setting Location of DiagramLink Labels to X/Y Coordinates
« Reply #3 on: March 14, 2019, 11:34:54 am »
Thanks for getting back to me Geert,  I will try another tack on this one that avoids the need.
qwerty,  It's the label that appears on a connector if you give it a name.  DiagramLink is the API object for it.   You can hide or show the label using the API, but not much else.
Rich Anderson
Urgnt Limited

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Setting Location of DiagramLink Labels to X/Y Coordinates
« Reply #4 on: March 14, 2019, 05:37:21 pm »
Uh, I was thinking about something totally different xD

Will have a look.

q.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Setting Location of DiagramLink Labels to X/Y Coordinates
« Reply #5 on: March 14, 2019, 06:31:32 pm »
See section 2.5.1 Geometry and Label Formatting of my Inside book. It's pretty detailed.

q.

Rich Anderson

  • EA User
  • **
  • Posts: 142
  • Karma: +8/-0
    • View Profile
    • LinkedIn
Re: Setting Location of DiagramLink Labels to X/Y Coordinates
« Reply #6 on: March 18, 2019, 10:05:23 am »
Thanks, Thomas for the reference.  I have your book!   :).   It looks, however that the label format tags (OX, and OY) are offsets from the default position where EA would place the label. In the application I have, I would want to make these an absolute position, I think.  I suppose I could use one of the source or destination "role" labels, but I will have to think about that.  Right now, I'm pursuing a different approach that involves generating the information to a grid in Excel that seems to be working reasonably well as an alternative.  (This is kind of a strange use case).  I shall see how it goes. Thanks, again, for your help.
Rich Anderson
Urgnt Limited

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Setting Location of DiagramLink Labels to X/Y Coordinates
« Reply #7 on: March 18, 2019, 05:49:43 pm »
Actually I did not go into the last details of these number - just that they correlate with the label position. I'll look into that during the week to find out what the real numbers actually mean.

q.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Setting Location of DiagramLink Labels to X/Y Coordinates
« Reply #8 on: March 18, 2019, 11:12:49 pm »
So, here's what I found out: the bottom middle point of the label text is the one reference point (more or less possible to calculate; you need to know the font and it's measures). The other reference point is a bit  more tricky: it's the middle of the connector. For a straight connector this is easy as you need simple arithmetics. Euclide is your friend. For links with bending points you need to iterate the Path list, calculate the total length and find the piece where the middle is located. Again Euclide is your friend. But you need him to be more friendly for that :-)

q.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Setting Location of DiagramLink Labels to X/Y Coordinates
« Reply #9 on: March 19, 2019, 09:33:57 am »
For links with bending points you need to iterate the Path list, calculate the total length and find the piece where the middle is located. Again Euclide is your friend. But you need him to be more friendly for that :-)
Actually, it's much simpler than that. It's the center point of the center segment.

Hopefully that allows you to be a little less chummy with Euclide.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Setting Location of DiagramLink Labels to X/Y Coordinates
« Reply #10 on: March 19, 2019, 09:53:56 am »
Hehe, should have guessed that ;-) So with even number of segments it the middle bending point.

q.

Rich Anderson

  • EA User
  • **
  • Posts: 142
  • Karma: +8/-0
    • View Profile
    • LinkedIn
Re: Setting Location of DiagramLink Labels to X/Y Coordinates
« Reply #11 on: March 19, 2019, 11:34:12 am »
Wow.  I didn't expect all that!  I think I will have to leave Euclid alone for now.
Rich Anderson
Urgnt Limited

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Setting Location of DiagramLink Labels to X/Y Coordinates
« Reply #12 on: March 19, 2019, 05:26:28 pm »
Hehe, should have guessed that ;-) So with even number of segments it the middle bending point.

q.
It's always in the middle of a segment. You can see where in EA by selecting one of the center labels.

You'll want something like
n=(int)points.count/2
x=(points[n].x+points[n+1].x)/2
y=(points[n].y+points[n+1].y)/2

Although the start and end points will be derived from the object positions.
« Last Edit: March 19, 2019, 06:02:18 pm by Eve »