<commit_before>import { GraphicalInstantaniousDynamicExpression } from "../GraphicalInstantaniousDynamicExpression";
import { InstantaniousDynamicExpression, DynamicEnum } from "../../VoiceData/Expressions/InstantaniousDynamicExpression";
import { GraphicalStaffEntry } from "../GraphicalStaffEntry";
import { GraphicalLabel } from "../GraphicalLabel";
import { Label } from "../../Label";
import { TextAlignment } from "../../../Common/Enums/TextAlignment";
import { EngravingRules } from "../EngravingRules";
import { FontStyles } from "../../../Common/Enums/FontStyles";
import { SkyBottomLineCalculator } from "../SkyBottomLineCalculator";
import { StaffLine } from "../StaffLine";
import { GraphicalMeasure } from "../GraphicalMeasure";
import { MusicSystem } from "../MusicSystem";

export class VexFlowInstantaniousDynamicExpression extends GraphicalInstantaniousDynamicExpression {
    private mInstantaniousDynamicExpression: InstantaniousDynamicExpression;
    private mLabel: GraphicalLabel;

    constructor(instantaniousDynamicExpression: InstantaniousDynamicExpression, staffEntry: GraphicalStaffEntry) {
        super();
        this.mInstantaniousDynamicExpression = instantaniousDynamicExpression;
        this.mLabel = new GraphicalLabel(new Label(this.Expression),
                                         EngravingRules.Rules.ContinuousDynamicTextHeight,
                                         TextAlignment.LeftTop,
                                         staffEntry.PositionAndShape);
        // FIXME: Add offset when skyline available
        // const offset: number = staffEntry.parentMeasure.ParentStaffLine.SkyBottomCalculator ...
        const offset: number = 5.5;
        this.mLabel.PositionAndShape.RelativePosition.y += offset;
        this.mLabel.Label.fontStyle = FontStyles.BoldItalic;
    }

    public calculcateBottomLine(measure: GraphicalMeasure): void {
        const skyBottomLineCalculator: SkyBottomLineCalculator = measure.ParentStaffLine.SkyBottomLineCalculator;
        const staffLine: StaffLine = measure.ParentStaffLine;
        const musicSystem: MusicSystem = measure.parentMusicSystem;

        // calculate LabelBoundingBox and set PSI parent
        this.mLabel.setLabelPositionAndShapeBorders();
        this.mLabel.PositionAndShape.Parent = musicSystem.PositionAndShape;

        // calculate relative Position
        const relativeX: number = staffLine.PositionAndShape.RelativePosition.x +
        measure.PositionAndShape.RelativePosition.x - this.mLabel.PositionAndShape.BorderMarginLeft;
        let relativeY: number;

        // and the corresponding SkyLine indeces
        let start: number = relativeX;
        let end: number = relativeX - this.mLabel.PositionAndShape.BorderLeft + this.mLabel.PositionAndShape.BorderMarginRight;

          // take into account the InstrumentNameLabel's at the beginning of the first MusicSystem
        if (staffLine === musicSystem.StaffLines[0] && musicSystem === musicSystem.Parent.MusicSystems[0]) {
              start -= staffLine.PositionAndShape.RelativePosition.x;
              end -= staffLine.PositionAndShape.RelativePosition.x;
          }

          // get the minimum corresponding SkyLine value
        const bottomLineMaxValue: number = skyBottomLineCalculator.getBottomLineMaxInRange(start, end);
        relativeY = bottomLineMaxValue;
        console.log(start, end, relativeY, this.mLabel.PositionAndShape.BorderMarginBottom)
        skyBottomLineCalculator.updateBottomLineInRange(start, end, relativeY + this.mLabel.PositionAndShape.BorderMarginBottom);
    }

    get Expression(): string {
        return DynamicEnum[this.mInstantaniousDynamicExpression.DynEnum];
    }

    get Label(): GraphicalLabel {
        return this.mLabel;<commit_msg>fix(Added skyline calculation to dynamic labels): labels affect height of skyline now. Start and end 2nd try<commit_after>import { GraphicalInstantaniousDynamicExpression } from "../GraphicalInstantaniousDynamicExpression";
import { InstantaniousDynamicExpression, DynamicEnum } from "../../VoiceData/Expressions/InstantaniousDynamicExpression";
import { GraphicalStaffEntry } from "../GraphicalStaffEntry";
import { GraphicalLabel } from "../GraphicalLabel";
import { Label } from "../../Label";
import { TextAlignment } from "../../../Common/Enums/TextAlignment";
import { EngravingRules } from "../EngravingRules";
import { FontStyles } from "../../../Common/Enums/FontStyles";
import { SkyBottomLineCalculator } from "../SkyBottomLineCalculator";
import { StaffLine } from "../StaffLine";
import { GraphicalMeasure } from "../GraphicalMeasure";
import { MusicSystem } from "../MusicSystem";

export class VexFlowInstantaniousDynamicExpression extends GraphicalInstantaniousDynamicExpression {
    private mInstantaniousDynamicExpression: InstantaniousDynamicExpression;
    private mLabel: GraphicalLabel;

    constructor(instantaniousDynamicExpression: InstantaniousDynamicExpression, staffEntry: GraphicalStaffEntry) {
        super();
        this.mInstantaniousDynamicExpression = instantaniousDynamicExpression;
        this.mLabel = new GraphicalLabel(new Label(this.Expression),
                                         EngravingRules.Rules.ContinuousDynamicTextHeight,
                                         TextAlignment.LeftTop,
                                         staffEntry.PositionAndShape);
        // FIXME: Add offset when skyline available
        // const offset: number = staffEntry.parentMeasure.ParentStaffLine.SkyBottomCalculator ...
        const offset: number = 5.5;
        this.mLabel.PositionAndShape.RelativePosition.y += offset;
        this.mLabel.Label.fontStyle = FontStyles.BoldItalic;
    }

    public calculcateBottomLine(measure: GraphicalMeasure): void {
        const skyBottomLineCalculator: SkyBottomLineCalculator = measure.ParentStaffLine.SkyBottomLineCalculator;
        const staffLine: StaffLine = measure.ParentStaffLine;
        const musicSystem: MusicSystem = measure.parentMusicSystem;

        // calculate LabelBoundingBox and set PSI parent
        this.mLabel.setLabelPositionAndShapeBorders();
        this.mLabel.PositionAndShape.Parent = musicSystem.PositionAndShape;

        // calculate relative Position
        const relativeX: number = staffLine.PositionAndShape.RelativePosition.x +
        measure.PositionAndShape.RelativePosition.x - this.mLabel.PositionAndShape.BorderMarginLeft;
        let relativeY: number;

        // and the corresponding SkyLine indeces
        let start: number = relativeX;
        let end: number = relativeX - this.mLabel.PositionAndShape.BorderLeft + this.mLabel.PositionAndShape.BorderMarginRight;

          // take into account the InstrumentNameLabel's at the beginning of the first MusicSystem
        if (staffLine === musicSystem.StaffLines[0] && musicSystem === musicSystem.Parent.MusicSystems[0]) {
              start -= staffLine.PositionAndShape.RelativePosition.x;
              end -= staffLine.PositionAndShape.RelativePosition.x;
          }

          // get the minimum corresponding SkyLine value
        const bottomLineMaxValue: number = skyBottomLineCalculator.getBottomLineMaxInRange(start, end);
        relativeY = bottomLineMaxValue;
        // console.log(start, end, relativeY, this.mLabel.PositionAndShape.BorderMarginBottom)
        skyBottomLineCalculator.updateBottomLineInRange(start, end, relativeY + this.mLabel.PositionAndShape.BorderMarginBottom);
    }

    get Expression(): string {
        return DynamicEnum[this.mInstantaniousDynamicExpression.DynEnum];
    }

    get Label(): GraphicalLabel {
        return this.mLabel;
{'fraction_non_alphanumeric': 0.08779723020642802, 'fraction_numerical': 0.0011758557616932323, 'mean_word_length': 3.4019551466359976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2372890', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1859, 'n_words': 407}