<commit_before>/*
 * Copyright <NAME> 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

class Link implements DiagramElement {

    private logicalId: string;
    private jointObject: joint.dia.Link;
    private constPropertiesPack: PropertiesPack;
    private changeableProperties: Map<Property> = {};
    private name = "Link"
    private type = "ControlFlow";

    constructor(jointObject: joint.dia.Link, properties: Map<Property>) {
        this.logicalId = UIDGenerator.generate();
        this.constPropertiesPack = this.getDefaultConstPropertiesPack();

        this.jointObject = jointObject;
        this.changeableProperties = properties;
        if (properties["Guard"].value) {
            this.jointObject.label(0, {
                position: 0.5,
                attrs: {
                    text: {
                        text: properties["Guard"].value , 'font-size': 14
                    }
                }
            });
        }
        this.updateHighlight();

        jointObject.on('change:source', () => {
                this.updateHighlight();
            }
        );

        jointObject.on('change:target', () => {
                this.updateHighlight();
            }
        );
    }

    getLogicalId(): string {
        return this.logicalId;
    }

    getJointObject() {
        return this.jointObject;
    }

    getName(): string {
        return this.name;
    }

    getType(): string {
        return this.type;
    }

    getConstPropertiesPack(): PropertiesPack {
        return this.constPropertiesPack;
    }

    getChangeableProperties(): Map<Property> {
        return this.changeableProperties;
    }

    setProperty(key: string, property: Property): void {
        this.changeableProperties[key] = property;
        if (key === "Guard" && property.value) {
            this.jointObject.label(0, {
                position: 0.5,
                attrs: {
                    text: {
                        text: property.value , 'font-size': 14
                    }
                }
            });
        }
    }

    private getDefaultConstPropertiesPack(): PropertiesPack {
        var logical: Map<Property> = this.initConstLogicalProperties();
        var graphical: Map<Property> = this.initConstGraphicalProperties();
        return new PropertiesPack(logical, graphical);
    }

    private initConstLogicalProperties(): Map<Property> {
        var logical: Map<Property> = {};
        logical["name"] = new Property("name", "QString", this.name);
        logical["linkShape"] = new Property("linkShape", "int", "-1");
        logical["outgoingExplosion"] = new Property("outgoingExplosion", "qReal::Id", "qrm:/");
        return logical;
    }

    private initConstGraphicalProperties(): Map<Property> {
        var graphical: Map<Property> = {};
        graphical["name"] = new Property("name", "QString", this.name);
        graphical["configuration"] = new Property("configuration", "QPolygon", "0, 0 : 0, 0 : ");
        graphical["fromPort"] = new Property("fromPort", "double", "0");
        graphical["toPort"] = new Property("toPort", "double", "0");
        graphical["position"] = new Property("position", "QPointF", "0, 0");
        return graphical;
    }

    private updateHighlight(): void {
        if (!this.jointObject.get('target').id || !this.jointObject.get('source').id) {
            this.jointObject.attr({
                    '.connection': {stroke: 'red'},
                    '.marker-target': {fill: 'red', d: 'M 10 0 L 0 5 L 10 10 z'}
                }
            );
        } else {
            this.jointObject.attr({
                    '.connection': {stroke: 'black'},
                    '.marker-target': {fill: 'black', d: 'M 10 0 L 0 5 L 10 10 z'}
                }
            );
        }
    }
}<commit_msg>fixed bug with empty label<commit_after>/*
 * Copyright <NAME> 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

class Link implements DiagramElement {

    private logicalId: string;
    private jointObject: joint.dia.Link;
    private constPropertiesPack: PropertiesPack;
    private changeableProperties: Map<Property> = {};
    private name = "Link"
    private type = "ControlFlow";

    constructor(jointObject: joint.dia.Link, properties: Map<Property>) {
        this.logicalId = UIDGenerator.generate();
        this.constPropertiesPack = this.getDefaultConstPropertiesPack();

        this.jointObject = jointObject;
        this.changeableProperties = properties;
        this.changeLabel(properties["Guard"].value);
        this.updateHighlight();

        jointObject.on('change:source', () => {
                this.updateHighlight();
            }
        );

        jointObject.on('change:target', () => {
                this.updateHighlight();
            }
        );
    }

    getLogicalId(): string {
        return this.logicalId;
    }

    getJointObject() {
        return this.jointObject;
    }

    getName(): string {
        return this.name;
    }

    getType(): string {
        return this.type;
    }

    getConstPropertiesPack(): PropertiesPack {
        return this.constPropertiesPack;
    }

    getChangeableProperties(): Map<Property> {
        return this.changeableProperties;
    }

    setProperty(key: string, property: Property): void {
        this.changeableProperties[key] = property;
        if (key === "Guard") {
            this.changeLabel(property.value);
        }
    }

    private changeLabel(value: string): void {
        this.jointObject.label(0, {
            position: 0.5,
            attrs: {
                text: {
                    text: value , 'font-size': 14
                }
            }
        });
    }

    private getDefaultConstPropertiesPack(): PropertiesPack {
        var logical: Map<Property> = this.initConstLogicalProperties();
        var graphical: Map<Property> = this.initConstGraphicalProperties();
        return new PropertiesPack(logical, graphical);
    }

    private initConstLogicalProperties(): Map<Property> {
        var logical: Map<Property> = {};
        logical["name"] = new Property("name", "QString", this.name);
        logical["linkShape"] = new Property("linkShape", "int", "-1");
        logical["outgoingExplosion"] = new Property("outgoingExplosion", "qReal::Id", "qrm:/");
        return logical;
    }

    private initConstGraphicalProperties(): Map<Property> {
        var graphical: Map<Property> = {};
        graphical["name"] = new Property("name", "QString", this.name);
        graphical["configuration"] = new Property("configuration", "QPolygon", "0, 0 : 0, 0 : ");
        graphical["fromPort"] = new Property("fromPort", "double", "0");
        graphical["toPort"] = new Property("toPort", "double", "0");
        graphical["position"] = new Property("position", "QPointF", "0, 0");
        return graphical;
    }

    private updateHighlight(): void {
        if (!this.jointObject.get('target').id || !this.jointObject.get('source').id) {
            this.jointObject.attr({
                    '.connection': {stroke: 'red'},
                    '.marker-target': {fill: 'red', d: 'M 10 0 L 0 5 L 10 10 z'}
                }
            );
        } else {
            this.jointObject.attr({
                    '.connection': {stroke: 'black'},
                    '.marker-target': {fill: 'black', d: 'M 10 0 L 0 5 L 10 10 z'}
                }
            );
        }
    }
}
{'fraction_non_alphanumeric': 0.127420878601795, 'fraction_numerical': 0.009093056211620217, 'mean_word_length': 2.181442524417731, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6984278', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2186, 'n_words': 582}