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++;
}
}
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);
}
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();
}
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)");
}
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);
}
Aggregations