Search in sources :

Example 11 with GraphLabels

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

the class GraphVisualAccess method recalculateTopLabels.

private void recalculateTopLabels(final ReadableGraph readGraph) {
    final GraphLabels topLabels = graphTopLabels != Graph.NOT_FOUND ? readGraph.getObjectValue(graphTopLabels, 0) : VisualGraphDefaults.DEFAULT_TOP_LABELS;
    final int numLabels = topLabels.getNumberOfLabels();
    topLabelAttrs = new int[numLabels];
    topLabelSizes = new float[numLabels];
    topLabelColors = new ConstellationColor[numLabels];
    int i = 0;
    for (final GraphLabel label : topLabels.getLabels()) {
        topLabelAttrs[i] = readGraph.getAttribute(GraphElementType.VERTEX, label.getAttributeName());
        topLabelSizes[i] = label.getSize();
        topLabelColors[i] = label.getColor() != null ? label.getColor() : VisualGraphDefaults.DEFAULT_LABEL_COLOR;
        i++;
    }
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Example 12 with GraphLabels

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

the class SaveGraphUtilities method makeGraphInteractable.

private static void makeGraphInteractable(final GraphWriteMethods graph) {
    // add attributes required for interaction
    // graph
    VisualConcept.GraphAttribute.CAMERA.ensure(graph);
    VisualConcept.GraphAttribute.CONNECTION_MODE.ensure(graph);
    VisualConcept.GraphAttribute.DRAWING_MODE.ensure(graph);
    // vertex
    VisualConcept.VertexAttribute.X.ensure(graph);
    VisualConcept.VertexAttribute.Y.ensure(graph);
    VisualConcept.VertexAttribute.Z.ensure(graph);
    VisualConcept.VertexAttribute.SELECTED.ensure(graph);
    // transaction
    VisualConcept.TransactionAttribute.SELECTED.ensure(graph);
    final int bottomLabelsAttribute = VisualConcept.GraphAttribute.BOTTOM_LABELS.ensure(graph);
    final GraphLabels newBottomLabels = new GraphLabels(Arrays.asList(new GraphLabel(VisualConcept.VertexAttribute.LABEL.getName(), ConstellationColor.AZURE)));
    graph.setObjectValue(bottomLabelsAttribute, 0, newBottomLabels);
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Example 13 with GraphLabels

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

the class VertexGraphLabelsAttributeInteraction method getDisplayText.

@Override
public String getDisplayText(final Object value) {
    if (value == null) {
        return null;
    }
    final GraphLabels labelsValue = ((GraphLabels) value);
    final StringBuilder labelsString = new StringBuilder();
    labelsValue.getLabels().forEach(label -> {
        labelsString.append(label.getAttributeName());
        labelsString.append(": (");
        labelsString.append(label.getColor());
        labelsString.append("), ");
    });
    return labelsString.length() > 0 ? labelsString.substring(0, labelsString.length() - 2) : labelsString.toString();
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels)

Example 14 with GraphLabels

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

the class TransactionGraphLabelsAttributeInteractionNGTest method testGetDisplayText.

/**
 * Test of getDisplayText method, of class TransactionGraphLabelsAttributeInteraction.
 */
@Test
public void testGetDisplayText() {
    System.out.println("getDisplayText");
    final TransactionGraphLabelsAttributeInteraction instance = new TransactionGraphLabelsAttributeInteraction();
    final String nullResult = instance.getDisplayText(null);
    assertNull(nullResult);
    final GraphLabels emptyLabels = new GraphLabels(Collections.emptyList());
    final String emptyGraphLabelsResult = instance.getDisplayText(emptyLabels);
    assertEquals(emptyGraphLabelsResult, "");
    final GraphLabel testLabel1 = new GraphLabel("test1", ConstellationColor.BANANA, 5F);
    final GraphLabel testLabel2 = new GraphLabel("test2", ConstellationColor.getColorValue(0.1F, 0.2F, 0.3F, 1F), 7F);
    final GraphLabels labels = new GraphLabels(Arrays.asList(testLabel1, testLabel2));
    final String graphLabelsResult = instance.getDisplayText(labels);
    assertEquals(graphLabelsResult, "test1: (Banana), test2: (#19334c)");
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel) Test(org.testng.annotations.Test)

Example 15 with GraphLabels

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

the class AbstractGraphLabelsIOProviderNGTest method testReadObject.

/**
 * Test of readObject method, of class AbstractGraphLabelsIOProvider.
 */
@Test
public void testReadObject() throws Exception {
    System.out.println("AbstractGraphLabelsIOProviderNGTest.testReadObject");
    // Test case where isNull returns true and isArray is false,
    resetMocking();
    when(mockJsonNode.isNull()).thenReturn(true);
    when(mockJsonNode.isArray()).thenReturn(false);
    instance.readObject(attributeId, elementId, mockJsonNode, mockGraphWriteMethods, null, null, null, null);
    Mockito.verify(mockJsonNode, times(0)).textValue();
    Mockito.verify(mockGraphWriteMethods, times(0)).setObjectValue(anyInt(), anyInt(), any(GraphAttribute.class));
    Mockito.verify(mockGraphWriteMethods, times(1)).setStringValue(attributeId, elementId, null);
    // Test case where isNull returns false but isArray is true, the jnode returns string
    resetMocking();
    when(mockJsonNode.isNull()).thenReturn(false);
    when(mockJsonNode.isArray()).thenReturn(false);
    when(mockJsonNode.textValue()).thenReturn(attribValue);
    instance.readObject(attributeId, elementId, mockJsonNode, mockGraphWriteMethods, null, null, null, null);
    Mockito.verify(mockJsonNode, times(1)).textValue();
    Mockito.verify(mockGraphWriteMethods, times(0)).setObjectValue(anyInt(), anyInt(), any(GraphAttribute.class));
    Mockito.verify(mockGraphWriteMethods, times(1)).setStringValue(attributeId, elementId, attribValue);
    // Test case where isNull returns true and isArray is true (in reality this isnt possible unless there was a
    // bug in JsonNode
    resetMocking();
    when(mockJsonNode.isNull()).thenReturn(true);
    when(mockJsonNode.isArray()).thenReturn(true);
    instance.readObject(attributeId, elementId, mockJsonNode, mockGraphWriteMethods, null, null, null, null);
    Mockito.verify(mockJsonNode, times(0)).textValue();
    Mockito.verify(mockGraphWriteMethods, times(0)).setObjectValue(anyInt(), anyInt(), any(GraphAttribute.class));
    Mockito.verify(mockGraphWriteMethods, times(1)).setStringValue(attributeId, elementId, null);
    // Test case where a valid non null array exists
    final ObjectMapper mapper = new ObjectMapper();
    final JsonNode testNode = mapper.readTree("[{\"attribute_name\":\"test_name1\",\"color\":{\"name\":\"red\"},\"radius\":0.1},{\"attribute_name\":\"test_name2\",\"color\":{\"name\":\"blue\"},\"radius\":0.2}]");
    resetMocking();
    when(mockJsonNode.isNull()).thenReturn(false);
    when(mockJsonNode.isArray()).thenReturn(true);
    instance.readObject(attributeId, elementId, testNode, mockGraphWriteMethods, null, null, null, null);
    Mockito.verify(mockGraphWriteMethods, times(0)).setStringValue(anyInt(), anyInt(), anyString());
    Mockito.verify(mockGraphWriteMethods, times(1)).setObjectValue(captorAtributeId.capture(), captorElementId.capture(), captorAttrVal.capture());
    GraphLabels labels = (GraphLabels) captorAttrVal.getValue();
    assertEquals((int) captorAtributeId.getValue(), attributeId);
    assertEquals((int) captorElementId.getValue(), elementId);
    assertEquals(labels.getNumberOfLabels(), 2);
    assertEquals(labels.getLabels().get(0).getAttributeName(), "test_name1");
    assertEquals(labels.getLabels().get(1).getAttributeName(), "test_name2");
    assertEquals(labels.getLabels().get(0).getColor(), ConstellationColor.RED);
    assertEquals(labels.getLabels().get(1).getColor(), ConstellationColor.BLUE);
    assertEquals(labels.getLabels().get(0).getSize(), 0.1f);
    assertEquals(labels.getLabels().get(1).getSize(), 0.2f);
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) JsonNode(com.fasterxml.jackson.databind.JsonNode) GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Aggregations

GraphLabels (au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels)20 GraphLabel (au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)16 ArrayList (java.util.ArrayList)6 Test (org.testng.annotations.Test)6 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 VertexDecorators (au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators)2 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)2 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)2 Arrays (java.util.Arrays)2 List (java.util.List)2 ServiceProvider (org.openide.util.lookup.ServiceProvider)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)1 GraphConstants (au.gov.asd.tac.constellation.graph.GraphConstants)1 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)1 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)1 BooleanAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.BooleanAttributeDescription)1 FloatAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.FloatAttributeDescription)1 StringAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.StringAttributeDescription)1 InteractiveGraphPluginRegistry (au.gov.asd.tac.constellation.graph.interaction.InteractiveGraphPluginRegistry)1