Search in sources :

Example 1 with ColorAttributeDescription

use of au.gov.asd.tac.constellation.graph.schema.visual.attribute.ColorAttributeDescription in project constellation by constellation-app.

the class TimelinePanel method updateTimeline.

public void updateTimeline(final GraphReadMethods graph, final boolean selectedOnly, final ZoneId zoneId) {
    final XYChart.Series<Number, Number> series = new XYChart.Series<>();
    // Graph attribute ids:
    final String colorAttrDesc = new ColorAttributeDescription().getName();
    final int colorTransAttr = graph.getAttribute(GraphElementType.TRANSACTION, colorAttrDesc);
    final int colorVertAttr = graph.getAttribute(GraphElementType.VERTEX, colorAttrDesc);
    final int selectedTransAttr = VisualConcept.TransactionAttribute.SELECTED.get(graph);
    final int selectedVertAttr = VisualConcept.VertexAttribute.SELECTED.get(graph);
    final int labelVertAttr = graph.getAttribute(GraphElementType.VERTEX, nodeLabelAttr);
    long lowestObservedY = Long.MAX_VALUE;
    long highestObservedY = Long.MIN_VALUE;
    for (final TreeElement element : clusteringManager.getElementsToDraw()) {
        XYChart.Data<Number, Number> nodeItem = element.getNodeItem();
        if (nodeItem == null) {
            if (element instanceof TreeLeaf) {
                final TreeLeaf leaf = (TreeLeaf) element;
                final int transactionID = leaf.getId();
                // Get the color for this transaction:
                ConstellationColor col = ConstellationColor.getColorValue(graph.getStringValue(colorTransAttr, transactionID));
                final Color transColor = col != null ? new Color(col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha()) : FALLBACK_COLOUR;
                // Get the selection status for the transaction:
                final boolean transSelected = graph.getBooleanValue(selectedTransAttr, transactionID);
                // Get the source and destination vertices, and their respective colors:
                final int sourceA = graph.getTransactionSourceVertex(transactionID);
                final int sourceB = graph.getTransactionDestinationVertex(transactionID);
                // Get the color for each vertex:
                col = ConstellationColor.getColorValue(graph.getStringValue(colorVertAttr, sourceA));
                final Color sourceAColor = col != null ? new Color(col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha()) : FALLBACK_COLOUR;
                col = ConstellationColor.getColorValue(graph.getStringValue(colorVertAttr, sourceB));
                final Color sourceBColor = col != null ? new Color(col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha()) : FALLBACK_COLOUR;
                // Get the selection state for each vertex:
                final boolean sourceASelected = graph.getBooleanValue(selectedVertAttr, sourceA);
                final boolean sourceBSelected = graph.getBooleanValue(selectedVertAttr, sourceB);
                // Get the label for each vertex:
                String sourceALabel = null;
                String sourceBLabel = null;
                if (labelVertAttr != Graph.NOT_FOUND) {
                    sourceALabel = graph.getStringValue(labelVertAttr, sourceA);
                    sourceBLabel = graph.getStringValue(labelVertAttr, sourceB);
                }
                boolean isElementSelected = GraphManager.getDefault().isElementSelected();
                isElementSelected |= sourceASelected || sourceBSelected || transSelected;
                GraphManager.getDefault().setElementSelected(isElementSelected);
                // Get the directionality of the transaction:
                final int directionality = graph.getTransactionDirection(transactionID);
                final Vertex vertexA;
                final Vertex vertexB;
                final Transaction transaction;
                if (sourceA > sourceB) {
                    vertexA = new Vertex(sourceA, sourceA, sourceALabel, sourceAColor, sourceASelected, transSelected, btnShowLabels.isSelected());
                    vertexB = new Vertex(sourceB, sourceB, sourceBLabel, sourceBColor, sourceBSelected, transSelected, btnShowLabels.isSelected());
                    if (directionality == Graph.DOWNHILL) {
                        final String label = labelMaker(sourceALabel, ARROW_CHAR, sourceBLabel);
                        transaction = new Transaction(transactionID, transColor, label, Transaction.DIRECTED_UP, transSelected);
                    } else if (directionality == Graph.UPHILL) {
                        throw new IllegalArgumentException("source > dest is always downhill");
                    } else {
                        // Undirected / Bi-directional
                        final String label = labelMaker(sourceALabel, '-', sourceBLabel);
                        transaction = new Transaction(transactionID, transColor, label, transSelected);
                    }
                } else if (sourceA < sourceB) {
                    vertexA = new Vertex(sourceB, sourceB, sourceBLabel, sourceBColor, sourceBSelected, transSelected, btnShowLabels.isSelected());
                    vertexB = new Vertex(sourceA, sourceA, sourceALabel, sourceAColor, sourceASelected, transSelected, btnShowLabels.isSelected());
                    if (directionality == Graph.DOWNHILL) {
                        throw new IllegalArgumentException("source < dest is always uphill");
                    // final String label = labelMaker(sourceBLabel, ARROW_CHAR, sourceALabel);
                    // transaction = new Transaction(transactionID, transColor, label, Transaction.DIRECTED_UP, transSelected);
                    } else if (directionality == Graph.UPHILL) {
                        final String label = labelMaker(sourceALabel, ARROW_CHAR, sourceBLabel);
                        transaction = new Transaction(transactionID, transColor, label, Transaction.DIRECTED_DOWN, transSelected);
                    } else {
                        // Undirected / Bi-directional
                        final String label = labelMaker(sourceBLabel, '-', sourceALabel);
                        transaction = new Transaction(transactionID, transColor, label, transSelected);
                    }
                } else {
                    // Same source and destination: a loop.
                    vertexA = new Vertex(sourceA, sourceA, sourceALabel, sourceAColor, sourceASelected, transSelected, btnShowLabels.isSelected());
                    vertexB = new Vertex(sourceA, sourceA, sourceALabel, sourceAColor, sourceASelected, transSelected, btnShowLabels.isSelected());
                    transaction = new Transaction(transactionID, transColor, sourceALabel, transSelected);
                }
                nodeItem = new XYChart.Data<>(leaf.getDatetime(), (Math.max(sourceA, sourceB) - Math.min(sourceA, sourceB)), new Interaction(vertexA, vertexB, transaction, btnShowLabels.isSelected()));
                element.setNodeItem(nodeItem);
            } else {
                nodeItem = new XYChart.Data<>(element.getLowerTimeExtent(), element.getLowerDisplayPos(), new Cluster(element.getLowerTimeExtent(), element.getUpperTimeExtent(), element.getLowerDisplayPos(), element.getUpperDisplayPos(), element.getCount(), element.getSelectedCount(), element.anyNodesSelected()));
                element.setNodeItem(nodeItem);
            }
        }
        if (nodeItem != null) {
            series.getData().add(nodeItem);
            lowestObservedY = Math.min(element.getLowerDisplayPos(), lowestObservedY);
            highestObservedY = Math.max(element.getUpperDisplayPos(), highestObservedY);
        }
    }
    timeline.populate(series, lowestObservedY, highestObservedY, selectedOnly, zoneId);
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) Vertex(au.gov.asd.tac.constellation.views.timeline.components.Vertex) ColorAttributeDescription(au.gov.asd.tac.constellation.graph.schema.visual.attribute.ColorAttributeDescription) Interaction(au.gov.asd.tac.constellation.views.timeline.components.Interaction) Color(javafx.scene.paint.Color) ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) TreeLeaf(au.gov.asd.tac.constellation.views.timeline.clustering.TreeLeaf) Cluster(au.gov.asd.tac.constellation.views.timeline.components.Cluster) TreeElement(au.gov.asd.tac.constellation.views.timeline.clustering.TreeElement) Transaction(au.gov.asd.tac.constellation.views.timeline.components.Transaction) XYChart(javafx.scene.chart.XYChart)

Aggregations

ColorAttributeDescription (au.gov.asd.tac.constellation.graph.schema.visual.attribute.ColorAttributeDescription)1 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)1 TreeElement (au.gov.asd.tac.constellation.views.timeline.clustering.TreeElement)1 TreeLeaf (au.gov.asd.tac.constellation.views.timeline.clustering.TreeLeaf)1 Cluster (au.gov.asd.tac.constellation.views.timeline.components.Cluster)1 Interaction (au.gov.asd.tac.constellation.views.timeline.components.Interaction)1 Transaction (au.gov.asd.tac.constellation.views.timeline.components.Transaction)1 Vertex (au.gov.asd.tac.constellation.views.timeline.components.Vertex)1 XYChart (javafx.scene.chart.XYChart)1 Color (javafx.scene.paint.Color)1