Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DoubleLinkTools with new linkTools API #1322

Open
ialokim opened this issue Jun 10, 2020 · 2 comments
Open

DoubleLinkTools with new linkTools API #1322

ialokim opened this issue Jun 10, 2020 · 2 comments

Comments

@ialokim
Copy link

ialokim commented Jun 10, 2020

I want to achieve a similar result to what has been possible before by setting

options: joint.util.defaults({
    doubleLinkTools: true,
}, joint.dia.LinkView.prototype.options)

on a custom linkView type using the new linkTools API.

I thought of different solutions how to handle the additional buttons for longer links, but I'm not sure if they are possible and what would be considered best practice:

  • hide and show a single linkTool using linkTool.hide/.show() depending on the link's length inside an UPDATE cycle
  • add or remove a single linkTool, e.g. Remove button, after setting the toolsView for the link by manipulation the toolsView's tools array
  • for each mouseover, create a completely new toolsView containing new (?) tools depending on how long the link is currently (this is how it was done in the link demo)

Also another related question: Is it also possible to change some options, e.g. the distance of a Button, after tool creation s.th. it would be possible to move them depending on the link's length?

@ialokim
Copy link
Author

ialokim commented Jun 10, 2020

Just for reference, I ended up overwriting the default Button show() and update() functions as follows:

joint.linkTools.Button.prototype.update = function() {
    if (this.relatedView.isShortLink())
        this.options.distance = this.options.distanceShort || this.options.distance;
    else
        this.options.distance = this.options.distanceLong || this.options.distance;
    this.position();
    return this;
};
joint.linkTools.Button.prototype.show = function() {
    if (this.options.secondary && this.relatedView.isShortLink()) return;
    this.el.style.display = '';
    this._visible = true;
};

The used LinkView needs then to have the corresponding .isShortLink() defined and using the options distanceLong, distanceShort and secondary at button creation enables showing additional buttons and repositioning them for long links.

@ialokim ialokim closed this as completed Jun 10, 2020
@kumilingus
Copy link
Contributor

You may also extend the Button class instead.

const MyButton = joint.linkTools.Button.extend({
  update: function() {
    if (this.relatedView.isShortLink())
        this.options.distance = this.options.distanceShort || this.options.distance;
    else
        this.options.distance = this.options.distanceLong || this.options.distance;
    this.position();
    return this;
  },
  show: function() {
    if (this.options.secondary && this.relatedView.isShortLink()) return;
    this.el.style.display = '';
    this._visible = true;
  }
});

Anyway, we could make distance option a callback (or add a new option - not sure at this point). So we could do stuff like this:

new joint.linkToolsButton({
  distance: function(linkView) {
    return (linkView.getConnectionLength() > 50) ? 20 : 10;
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants