<commit_before>// Style fliegt raus. Bloß noch ein String.

class ConnectionDefinitionGenerator { 

    generate(connections) {
        let result = {}
        connections.map(function(connection) {
            result.push(createConnection(connection))
        })
        return result;
    }

    createPlacingList(connection) {
        const result = connection.placings.map(this.createPlacing, this);
        return result;
    }

    createPlacing(placing) {
        const generatedPlacing = {
            position: placing.positionOffset
        }
        return Object.assign(generatedPlacing, this.createPlacingShape(placing));
    }

    createPlacingShape(placing) {
        const shape = placing.shape;

        // lieber statisches Object das die Funktionen hält

        switch(shape.type) {
            case 'Line': return this.generateLineShape(shape);
            case 'PolyLine': return this.generatePolyLineShape(shape);
            case 'Rectangle': return this.generateRectangleShape(shape, placing.positionDistance);
            case 'RoundedRectangle': return this.generateRoundedRectangleShape(shape, placing.positionDistance);
            case 'Ellipse': return this.generateEllipseShape(shape, placing.positionDistance);    
            case 'Text': return this.generateTextShape(shape);        
        }
    }

    styleGetCommonAttributes(style) {
        // TODO 
        return {"style": "dummy"}
    }

    generatePlacingShapeStyle(generatedShape, shape) {
        generatedShape.attrs = 'style' in shape ? Object.assign(generatedShape.attrs, this.styleGetCommonAttributes(shape.style)): generatedShape.attrs;
        return generatedShape;
    }

    generateLineShape(line) {
        const shape = {
            markup: '<line />',
            attrs: {
                x1: line.startPoint.x,
                y1: line.startPoint.y,
                x2: line.endPoint.x,
                y2: line.endPoint.y
            }
        };
        return this.generatePlacingShapeStyle(shape, line)
    }

    generatePolyLineShape(shape) {
        const polyLineShape = {
            markup: '<polyline />',
            attrs: {
                points: [
                    shape.points.map(function(point) {
                        
                    })
                       //+ shape.points.map(point => point.x + ", " + point.y + { if (point != shape.points.last) " " else "\"" }).mkString("") + raw
                ],
                fill: 'transparent'
            }
        };  

        if ('style' in polyLineShape) {
            return Object.assign(polyLineShape.attrs, this.stylegetCommonAttributes(shape.style));
        };
        return polyLineShape;
    }

    generatePoints(points) {
        let pointString = "";

        points.map(function(point) {
            pointString += (`${point.x}, ${point.y}, `)
        })
        pointString.pop().pop();
        pointString += "/";
    }
    
    generateRectangleShape(rectangle, distance) {
        const shape = {
            markup: '<rect />',
            attrs:{
                height: rectangle.sizeHeight,
                width: rectangle.sizeWidth,
                y: distance - rectangle.sizeHeight / 2
            }
        };
        return this.generatePlacingShapeStyle(shape, rectangle)
        
    }
    
    generateRoundedRectangleShape(roundedRectangle, distance) {
        const shape = {
            markup: '<rect />',
            attrs:{
                height: roundedRectangle.sizeHeight,
                width: roundedRectangle.sizeWidth,
                rx: roundedRectangle.curveWidth,
                ry: roundedRectangle.curveHeight,
                y: distance - roundedRectangle.sizeHeight / 2,
            }
        }
        return this.generatePlacingShapeStyle(shape, roundedRectangle)        
      }
    
      /*
      private def generatePlacingShape(shape: Polygon, distance: Int) = {
        """
        markup: '<polygon />',
        attrs:{
          points: """" + shape.points.map(point => point.x + "," + point.y + { if (point != shape.points.last) " " else "\"" }).mkString + raw""",
          ${if (shape.style.isDefined) StyleGenerator.commonAttributes(shape.style.get) else ""}
        }
        """
      }*/
    
    generateEllipseShape(ellipse, distance) {
        const shape = {
            markup: '<ellipse />',
            attrs:{
                rx: ellipse.sizeWidth / 2,
                ry: ellipse.sizeHeight / 2,
                cy: distance,
            }
        }
        return this.generatePlacingShapeStyle(shape, ellipse);   
    }
    
    generateTextShape(text) {
        return {
            markup: `<text>${text.textBody}</text>`,
            attrs:{
                y: text.sizeHeight / 2
            }
        };
    }
    
    createLabelList(connection) {
        const labels = connection.placings.filter(placing => placing.shape.type === 'Label');
        return labels.map(this.createLabel);
    }

    createLabel(placing) {
        return {
            position: placing.positionOffset,
            attrs: {
              rect: {fill: 'transparent'},
              text: {
                y: 'positionDistance' in placing ? placing.positionDistance : 0,
                text: placing.shape.textBody
              }
            },
            id: placing.shape.id
        };
    }

}

export default class Generator{
    constructor(connections) {
        this.connectionDefinitionGenerator = new ConnectionDefinitionGenerator()
        this.connections = connections
    }

    getConnectionStyle(styleName) {
        
    }

    getPlacings(styleName) {
        const connection = this.connections.filter(c => c.name === styleName);
        return connection.length === 1 ? this.connectionDefinitionGenerator.createPlacingList(connection.pop()) : []
    }

    getLabels(styleName) {
        const connection = this.connections.filter(c => c.name === styleName); // find
        return connection.length === 1 ? this.connectionDefinitionGenerator.createLabelList(connection.pop()) : []
    }
}<commit_msg>#29 change filter to find functions<commit_after>// Style fliegt raus. Bloß noch ein String.

class ConnectionDefinitionGenerator { 

    generate(connections) {
        let result = {}
        connections.map(function(connection) {
            result.push(createConnection(connection))
        })
        return result;
    }

    createPlacingList(connection) {
        const result = connection.placings.map(this.createPlacing, this);
        return result;
    }

    createPlacing(placing) {
        const generatedPlacing = {
            position: placing.positionOffset
        }
        return Object.assign(generatedPlacing, this.createPlacingShape(placing));
    }

    createPlacingShape(placing) {
        const shape = placing.shape;

        // lieber statisches Object das die Funktionen hält

        switch(shape.type) {
            case 'Line': return this.generateLineShape(shape);
            case 'PolyLine': return this.generatePolyLineShape(shape);
            case 'Rectangle': return this.generateRectangleShape(shape, placing.positionDistance);
            case 'RoundedRectangle': return this.generateRoundedRectangleShape(shape, placing.positionDistance);
            case 'Ellipse': return this.generateEllipseShape(shape, placing.positionDistance);    
            case 'Text': return this.generateTextShape(shape);        
        }
    }

    styleGetCommonAttributes(style) {
        // TODO 
        return {"style": "dummy"}
    }

    generatePlacingShapeStyle(generatedShape, shape) {
        generatedShape.attrs = 'style' in shape ? Object.assign(generatedShape.attrs, this.styleGetCommonAttributes(shape.style)): generatedShape.attrs;
        return generatedShape;
    }

    generateLineShape(line) {
        const shape = {
            markup: '<line />',
            attrs: {
                x1: line.startPoint.x,
                y1: line.startPoint.y,
                x2: line.endPoint.x,
                y2: line.endPoint.y
            }
        };
        return this.generatePlacingShapeStyle(shape, line)
    }

    generatePolyLineShape(shape) {
        const polyLineShape = {
            markup: '<polyline />',
            attrs: {
                points: [
                    shape.points.map(function(point) {
                        
                    })
                       //+ shape.points.map(point => point.x + ", " + point.y + { if (point != shape.points.last) " " else "\"" }).mkString("") + raw
                ],
                fill: 'transparent'
            }
        };  

        if ('style' in polyLineShape) {
            return Object.assign(polyLineShape.attrs, this.stylegetCommonAttributes(shape.style));
        };
        return polyLineShape;
    }

    generatePoints(points) {
        let pointString = "";

        points.map(function(point) {
            pointString += (`${point.x}, ${point.y}, `)
        })
        pointString.pop().pop();
        pointString += "/";
    }
    
    generateRectangleShape(rectangle, distance) {
        const shape = {
            markup: '<rect />',
            attrs:{
                height: rectangle.sizeHeight,
                width: rectangle.sizeWidth,
                y: distance - rectangle.sizeHeight / 2
            }
        };
        return this.generatePlacingShapeStyle(shape, rectangle)
        
    }
    
    generateRoundedRectangleShape(roundedRectangle, distance) {
        const shape = {
            markup: '<rect />',
            attrs:{
                height: roundedRectangle.sizeHeight,
                width: roundedRectangle.sizeWidth,
                rx: roundedRectangle.curveWidth,
                ry: roundedRectangle.curveHeight,
                y: distance - roundedRectangle.sizeHeight / 2,
            }
        }
        return this.generatePlacingShapeStyle(shape, roundedRectangle)        
      }
    
      /*
      private def generatePlacingShape(shape: Polygon, distance: Int) = {
        """
        markup: '<polygon />',
        attrs:{
          points: """" + shape.points.map(point => point.x + "," + point.y + { if (point != shape.points.last) " " else "\"" }).mkString + raw""",
          ${if (shape.style.isDefined) StyleGenerator.commonAttributes(shape.style.get) else ""}
        }
        """
      }*/
    
    generateEllipseShape(ellipse, distance) {
        const shape = {
            markup: '<ellipse />',
            attrs:{
                rx: ellipse.sizeWidth / 2,
                ry: ellipse.sizeHeight / 2,
                cy: distance,
            }
        }
        return this.generatePlacingShapeStyle(shape, ellipse);   
    }
    
    generateTextShape(text) {
        return {
            markup: `<text>${text.textBody}</text>`,
            attrs:{
                y: text.sizeHeight / 2
            }
        };
    }
    
    createLabelList(connection) {
        const labels = connection.placings.filter(placing => placing.shape.type === 'Label');
        return labels.map(this.createLabel);
    }

    createLabel(placing) {
        return {
            position: placing.positionOffset,
            attrs: {
              rect: {fill: 'transparent'},
              text: {
                y: 'positionDistance' in placing ? placing.positionDistance : 0,
                text: placing.shape.textBody
              }
            },
            id: placing.shape.id
        };
    }

}

export default class Generator{
    constructor(connections) {
        this.connectionDefinitionGenerator = new ConnectionDefinitionGenerator()
        this.connections = connections
    }

    getConnectionStyle(styleName) {
        
    }

    getPlacings(styleName) {
        const connection = this.connections.find(c => c.name === styleName);
        return connection ? this.connectionDefinitionGenerator.createPlacingList(connection) : [];
    }

    getLabels(styleName) {
        const connection = this.connections.find(c => c.name === styleName);
        return connection ? this.connectionDefinitionGenerator.createLabelList(connection) : [];
    }
}
{'fraction_non_alphanumeric': 0.11084595128373931, 'fraction_numerical': 0.0019749835418038184, 'mean_word_length': 1.7899449035812671, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '142166', 'n_tokens_mistral': 3264, 'n_tokens_neox': 3123, 'n_words': 580}