diff --git a/packages/joint-core/src/linkTools/RotateLabel.mjs b/packages/joint-core/src/linkTools/RotateLabel.mjs index 533bf3798..ece5df1c0 100644 --- a/packages/joint-core/src/linkTools/RotateLabel.mjs +++ b/packages/joint-core/src/linkTools/RotateLabel.mjs @@ -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) { diff --git a/packages/joint-core/types/joint.d.ts b/packages/joint-core/types/joint.d.ts index 9a3adf19c..64acef7f1 100644 --- a/packages/joint-core/types/joint.d.ts +++ b/packages/joint-core/types/joint.d.ts @@ -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; } }