use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel 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.GraphLabel 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.GraphLabel in project constellation by constellation-app.
the class VisualSchemaV4UpdateProvider method schemaUpdate.
@Override
protected void schemaUpdate(StoreGraph graph) {
boolean updateVertexKeys = false;
// update vertex identifier attribute
if (VisualConcept.VertexAttribute.IDENTIFIER.get(graph) == Graph.NOT_FOUND) {
updateVertexKeys = true;
}
// update vertex label attribute
final int oldVertexLabelAttributeId = graph.getAttribute(GraphElementType.VERTEX, LABEL_ATTRIBUTE_NAME);
if (oldVertexLabelAttributeId != GraphConstants.NOT_FOUND) {
graph.setPrimaryKey(GraphElementType.VERTEX);
final int newVertexLabelAttributeId = VisualConcept.VertexAttribute.LABEL.ensure(graph);
final int vertexIdentiferAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
for (int vertexPosition = 0; vertexPosition < graph.getVertexCount(); vertexPosition++) {
final int vertexId = graph.getVertex(vertexPosition);
final String labelValue = graph.getStringValue(oldVertexLabelAttributeId, vertexId);
graph.setStringValue(newVertexLabelAttributeId, vertexId, labelValue);
if (graph.getStringValue(vertexIdentiferAttributeId, vertexId) == null) {
graph.setStringValue(vertexIdentiferAttributeId, vertexId, labelValue);
}
}
graph.removeAttribute(oldVertexLabelAttributeId);
updateVertexKeys = true;
}
// update vertex keys and complete vertices
if (updateVertexKeys) {
final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.VERTEX);
final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
graph.setPrimaryKey(GraphElementType.VERTEX, keyAttributeIds);
}
// update vertex labels
final int vertexBottomLabelsAttributeId = VisualConcept.GraphAttribute.BOTTOM_LABELS.get(graph);
if (vertexBottomLabelsAttributeId != GraphConstants.NOT_FOUND) {
final GraphLabel label = new GraphLabel(VisualConcept.VertexAttribute.LABEL.getName(), graph.getSchema().getFactory().getVertexLabelColor());
graph.setObjectValue(vertexBottomLabelsAttributeId, 0, new GraphLabels(Arrays.asList(label)));
}
boolean updateTransactionKeys = false;
// update transaction identifier attribute
if (VisualConcept.TransactionAttribute.IDENTIFIER.get(graph) == Graph.NOT_FOUND) {
updateTransactionKeys = true;
}
final int oldTransactionUniqueIdAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, UNIQUE_ID_ATTRIBUTE_NAME);
if (oldTransactionUniqueIdAttributeId != GraphConstants.NOT_FOUND) {
graph.setPrimaryKey(GraphElementType.TRANSACTION);
final int newTransactionIdentifierAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(graph);
for (int transactionPosition = 0; transactionPosition < graph.getTransactionCount(); transactionPosition++) {
final int transactionId = graph.getTransaction(transactionPosition);
final String uniqueIdValue = graph.getStringValue(oldTransactionUniqueIdAttributeId, transactionId);
graph.setStringValue(newTransactionIdentifierAttributeId, transactionId, uniqueIdValue);
}
graph.removeAttribute(oldTransactionUniqueIdAttributeId);
updateTransactionKeys = true;
}
// update transaction label attribute
final int oldTransactionLabelAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, LABEL_ATTRIBUTE_NAME);
if (oldTransactionLabelAttributeId != GraphConstants.NOT_FOUND) {
graph.setPrimaryKey(GraphElementType.TRANSACTION);
final int newTransactionLabelAttributeId = VisualConcept.TransactionAttribute.LABEL.ensure(graph);
final int transactionIdentiferAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(graph);
for (int transactionPosition = 0; transactionPosition < graph.getTransactionCount(); transactionPosition++) {
final int transactionId = graph.getTransaction(transactionPosition);
final String labelValue = graph.getStringValue(oldTransactionLabelAttributeId, transactionId);
graph.setStringValue(newTransactionLabelAttributeId, transactionId, labelValue);
if (graph.getStringValue(transactionIdentiferAttributeId, transactionId) == null) {
graph.setStringValue(transactionIdentiferAttributeId, transactionId, labelValue);
}
}
graph.removeAttribute(oldTransactionLabelAttributeId);
updateTransactionKeys = true;
}
// update transaction keys and complete transactions
if (updateTransactionKeys) {
final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.TRANSACTION);
final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
graph.setPrimaryKey(GraphElementType.TRANSACTION, keyAttributeIds);
}
}
use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.
the class NodeGraphLabelsV1AttributeUpdateProvider method updateAttributeValue.
@Override
public Object updateAttributeValue(final Object value) {
if (value == null) {
return null;
}
final ElementGraphLabelsV0 v0 = (ElementGraphLabelsV0) value;
final List<ElementGraphLabelV0> labelsV0 = v0.getLabels();
final List<GraphLabel> labels = new ArrayList<>();
for (final ElementGraphLabelV0 labelV0 : labelsV0) {
final GraphLabel label = new GraphLabel(labelV0.getAttributeName(), labelV0.getColor(), labelV0.getSize());
labels.add(label);
}
return new GraphLabels(labels);
}
use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.
the class TransactionGraphLabelsV1AttributeUpdateProvider method updateAttributeValue.
@Override
public Object updateAttributeValue(final Object value) {
if (value == null) {
return null;
}
final ElementGraphLabelsV0 v0 = (ElementGraphLabelsV0) value;
final List<ElementGraphLabelV0> labelsV0 = v0.getLabels();
final List<GraphLabel> labels = new ArrayList<>();
for (final ElementGraphLabelV0 labelV0 : labelsV0) {
final GraphLabel label = new GraphLabel(labelV0.getAttributeName(), labelV0.getColor(), labelV0.getSize());
labels.add(label);
}
return new GraphLabels(labels);
}
Aggregations