<commit_before>package nl.tudelft.lifetiles.graph.view;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import nl.tudelft.lifetiles.annotation.model.GeneAnnotation;
import nl.tudelft.lifetiles.annotation.model.KnownMutation;
import nl.tudelft.lifetiles.graph.controller.GraphController;
import nl.tudelft.lifetiles.graph.model.Graph;
import nl.tudelft.lifetiles.sequence.Mutation;
import nl.tudelft.lifetiles.sequence.model.SequenceSegment;

/**
 * The TileView is responsible for displaying the graph given from
 * the TileController.
 *
 */
public class TileView {
    /**
     * Default color of a tile element.
     */
    private static Color defaultColor = Color.web("a1d3ff");
    /**
     * The edges contains all EdgeLines to be displayed.
     */
    private final Group edges;
    /**
     * The nodes contains all Vertices to be displayed.
     */
    private final Map<SequenceSegment, VertexView> nodemap;

    /**
     * The bookmarks group contains all bookmarks and annotations to be
     * displayed.
     */
    private final Group bookmarks;

    /**
     * The lanes list which contains the occupation of the lanes inside the
     * tileview.
     */
    private List<Long> lanes;

    /**
     * The factor to apply on the vertices and bookmarks to resize them.
     */
    private double scale;

    /**
     * Controller for the View.
     */
    private final GraphController controller;

    /**
     * Create the TileView by initializing the groups where the to be drawn
     * vertices and edges are stored.
     *
     * @param control
     *            The controller for the TileView
     */
    public TileView(final GraphController control) {
        controller = control;

        nodemap = new HashMap<SequenceSegment, VertexView>();
        edges = new Group();
        bookmarks = new Group();
    }

    /**
     * Draw the given graph.
     *
     * @param segments
     *            Graph to be drawn
     * @param graph
     *            Graph to base the edges on
     * @param knownMutations
     *            Map from segment to known mutations.
     * @param mappedAnnotations
     *            Map from segment to gene annotations.
     * @param scale
     *            the scale to resize all elements of the graph
     * @return the elements that must be displayed on the screen
     */
    public Group drawGraph(final Set<SequenceSegment> segments,
            final Graph<SequenceSegment> graph,
            final Map<SequenceSegment, List<KnownMutation>> knownMutations,
            final Map<SequenceSegment, List<GeneAnnotation>> mappedAnnotations,
            final double scale) {
        Group root = new Group();

        lanes = new ArrayList<Long>();
        this.scale = scale;

        for (SequenceSegment segment : segments) {
            List<KnownMutation> segKnownMutations = null;
            List<GeneAnnotation> segAnnotations = null;
            if (knownMutations != null && knownMutations.containsKey(segment)) {
                segKnownMutations = knownMutations.get(segment);
            }
            if (mappedAnnotations != null
                    && mappedAnnotations.containsKey(segment)) {
                segAnnotations = mappedAnnotations.get(segment);
            }
            drawVertexLane(segment, segKnownMutations, segAnnotations);
        }

        // TODO toggle edge drawing in the settings
        // drawEdges(graph);
        Group nodes = new Group();

        for (Entry<SequenceSegment, VertexView> entry : nodemap.entrySet()) {
            nodes.getChildren().add(entry.getValue());
        }

        root.getChildren().addAll(nodes, edges, bookmarks);
        return root;
    }

    // /**
    // * @param graph
    // * graph to draw the edges from
    // */
    // private void drawEdges(final Graph<SequenceSegment> graph) {
    // for (Edge<SequenceSegment> edge : graph.getAllEdges()) {
    // if (nodemap.containsKey(graph.getSource(edge))
    // && nodemap.containsKey(graph.getDestination(edge))) {
    //
    // VertexView source = nodemap.get(graph.getSource(edge));
    // VertexView destination = nodemap<commit_msg>Clear variable names "seg"<commit_after>package nl.tudelft.lifetiles.graph.view;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import nl.tudelft.lifetiles.annotation.model.GeneAnnotation;
import nl.tudelft.lifetiles.annotation.model.KnownMutation;
import nl.tudelft.lifetiles.graph.controller.GraphController;
import nl.tudelft.lifetiles.graph.model.Graph;
import nl.tudelft.lifetiles.sequence.Mutation;
import nl.tudelft.lifetiles.sequence.model.SequenceSegment;

/**
 * The TileView is responsible for displaying the graph given from
 * the TileController.
 *
 */
public class TileView {
    /**
     * Default color of a tile element.
     */
    private static Color defaultColor = Color.web("a1d3ff");
    /**
     * The edges contains all EdgeLines to be displayed.
     */
    private final Group edges;
    /**
     * The nodes contains all Vertices to be displayed.
     */
    private final Map<SequenceSegment, VertexView> nodemap;

    /**
     * The bookmarks group contains all bookmarks and annotations to be
     * displayed.
     */
    private final Group bookmarks;

    /**
     * The lanes list which contains the occupation of the lanes inside the
     * tileview.
     */
    private List<Long> lanes;

    /**
     * The factor to apply on the vertices and bookmarks to resize them.
     */
    private double scale;

    /**
     * Controller for the View.
     */
    private final GraphController controller;

    /**
     * Create the TileView by initializing the groups where the to be drawn
     * vertices and edges are stored.
     *
     * @param control
     *            The controller for the TileView
     */
    public TileView(final GraphController control) {
        controller = control;

        nodemap = new HashMap<SequenceSegment, VertexView>();
        edges = new Group();
        bookmarks = new Group();
    }

    /**
     * Draw the given graph.
     *
     * @param segments
     *            Graph to be drawn
     * @param graph
     *            Graph to base the edges on
     * @param knownMutations
     *            Map from segment to known mutations.
     * @param mappedAnnotations
     *            Map from segment to gene annotations.
     * @param scale
     *            the scale to resize all elements of the graph
     * @return the elements that must be displayed on the screen
     */
    public Group drawGraph(final Set<SequenceSegment> segments,
            final Graph<SequenceSegment> graph,
            final Map<SequenceSegment, List<KnownMutation>> knownMutations,
            final Map<SequenceSegment, List<GeneAnnotation>> mappedAnnotations,
            final double scale) {
        Group root = new Group();

        lanes = new ArrayList<Long>();
        this.scale = scale;

        for (SequenceSegment segment : segments) {
            List<KnownMutation> segmentKnownMutations = null;
            List<GeneAnnotation> segmentAnnotations = null;
            if (knownMutations != null && knownMutations.containsKey(segment)) {
                segmentKnownMutations = knownMutations.get(segment);
            }
            if (mappedAnnotations != null
                    && mappedAnnotations.containsKey(segment)) {
                segmentAnnotations = mappedAnnotations.get(segment);
            }
            drawVertexLane(segment, segmentKnownMutations, segmentAnnotations);
        }

        // TODO toggle edge drawing in the settings
        // drawEdges(graph);
        Group nodes = new Group();

        for (Entry<SequenceSegment, VertexView> entry : nodemap.entrySet()) {
            nodes.getChildren().add(entry.getValue());
        }

        root.getChildren().addAll(nodes, edges, bookmarks);
        return root;
    }

    // /**
    // * @param graph
    // * graph to draw the edges from
    // */
    // private void drawEdges(final Graph<SequenceSegment> graph) {
    // for (Edge<SequenceSegment> edge : graph.getAllEdges()) {
    // if (nodemap.containsKey(graph.getSource(edge))
    // && nodemap.containsKey(graph.getDestination(edge))) {
    //
    // VertexView source = nodemap.get(graph.getSource(edge));
    // VertexView destination = nodemap
{'fraction_non_alphanumeric': 0.09412035438959844, 'fraction_numerical': 0.0006903693476009665, 'mean_word_length': 2.376845376845377, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '2771993', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2343, 'n_words': 670}