Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kumilingus committed Sep 2, 2024
1 parent c2130dc commit edae089
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/joint-core/src/linkTools/RotateLabel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,27 @@ export const RotateLabel = Control.extend({

setPosition(view, coordinates) {
const model = view.model;
const index = this.options.labelIndex;
const label = model.label(index);
const label = this.getLabel();
if (!label) return;
const labelPosition = this.getLabelPosition(label);
const position = view.getLabelCoordinates(labelPosition);
const angle = 90 - position.theta(coordinates);
const index = this.getLabelIndex();
model.prop(['labels', index, 'position', 'angle'], angle);
},

resetPosition(view) {
const model = view.model;
const index = this.options.labelIndex;
const index = this.getLabelIndex();
model.prop(['labels', index, 'position', 'angle'], 0);
},

getLabelIndex() {
return this.options.labelIndex || 0;
},

getLabel() {
const { relatedView, options } = this;
return relatedView.model.label(options.labelIndex);
return this.relatedView.model.label(this.getLabelIndex()) || null;
},

getLabelPosition(label) {
Expand Down
4 changes: 4 additions & 0 deletions packages/joint-core/types/joint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4543,5 +4543,9 @@ export namespace linkTools {
constructor(opt?: RotateLabel.Options);

protected getLabelPosition(label: dia.Link.Label): dia.Link.LabelPosition;

protected getLabelIndex(): number;

protected getLabel(): dia.Link.Label | null;
}
}

0 comments on commit edae089

Please sign in to comment.