anseki / leader-line

Draw a leader line in your web page.
http://anseki.github.io/leader-line/
MIT License
3.03k stars 424 forks source link

LeaderLine.prototype.getInsProps #374

Closed calumk closed 2 years ago

calumk commented 2 years ago

Is there some way I cannot figure out, that would allow me to expose the insProps?

If not, Would you be opposed to adding the following funtion?

  LeaderLine.prototype.getInsProps = function() {
    return insProps[this._id]
  };

It would really simplify exercises where we want to work around / append / modify the line.

For example, in the following code, we can only do the following at the point where the Line is created, (it uses the last-child)

https://jsfiddle.net/zmc6jywv/

   const line = new LeaderLine(...args);
    if (!line.middleLabel) { line.middleLabel = '*'; }
    const elmSvg = document.querySelector('body > .leader-line:last-child'),
      elmText = elmSvg.querySelector('text'),
      bBox = elmText.getBBox(),
      centerX = bBox.x + bBox.width / 2,
      centerY = bBox.y + bBox.height / 2,

But this would allow us to do the followng - (and if we store "line" we can do this any-time)

    let line = new LeaderLine(...args);
    if (!line.middleLabel) { line.middleLabel = '*'; }
    let bBox = line.getInsProps().svg.querySelector('text').getBBox()
    let centerX = bBox.x + bBox.width / 2;
    let centerY = bBox.y + bBox.height / 2;
anseki commented 2 years ago

Hi @calumk, thank you for the comment. To begin with, the insProps was implemented to avoid accessing via API. That is, the properties are private fields in old ECMAScript. In other words, the insProps is not required if those are accessible, and those should be moved to instance properties. Therefore, your plan means breaking the API design above obviously. And also, that should make more problems. If you really want to do that, you can fork and customize the library to make a special one for your app. Or, you had better use another great library instead. The LeaderLine is inappropriate for your app maybe.

calumk commented 2 years ago

Is there some way you could consider modifying the API, such that it is possible to access the SVG, by accessing the line object, without breaking the api. I dont really mind how it exposes it, but access to the rendered SVG, from the PlainDraggable object, seems like a good idea?

For now i have forked the project

anseki commented 2 years ago

Sorry, my English is poor. Do you mean that you want to use LeaderLine with PlainDraggable and you can't do that?

calumk commented 2 years ago

Sorry - Typo

I dont really mind how it exposes it, but access to the rendered SVG, from the [LeaderLine] object, seems like a good idea?

anseki commented 2 years ago

No, that is not good idea. You should not change the code if you can't understand why the insProps exists. You had better use another great library instead. The LeaderLine is inappropriate for your app. You maybe need a library as helper for handling SVG, the LeaderLine is not.

calumk commented 2 years ago

I have used leader-line extensivly over the last few years - So i disagree that it is inappropriate, but it is your library, your choice.

https://www.youtube.com/watch?v=OBI3qEEFtBg&feature=youtu.be

anseki commented 2 years ago

You may understand that when you learn the ECMAScript. :smile: