use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.
the class SetRadiusForArrangement method getLabelAttributes.
private void getLabelAttributes() {
final int bottomLabelsAttr = VisualConcept.GraphAttribute.BOTTOM_LABELS.ensure(graph);
final int topLabelsAttr = VisualConcept.GraphAttribute.TOP_LABELS.ensure(graph);
final GraphLabels bottomLabels = graph.getObjectValue(bottomLabelsAttr, 0);
final GraphLabels topLabels = graph.getObjectValue(topLabelsAttr, 0);
labelAttrArray = new int[bottomLabels.getNumberOfLabels() + topLabels.getNumberOfLabels()];
labelSizeArray = new float[labelAttrArray.length];
int labelNum = 0;
for (final GraphLabel label : bottomLabels.getLabels()) {
labelAttrArray[labelNum] = graph.getAttribute(GraphElementType.VERTEX, label.getAttributeName());
labelSizeArray[labelNum++] = label.getSize();
}
for (final GraphLabel label : topLabels.getLabels()) {
labelAttrArray[labelNum] = graph.getAttribute(GraphElementType.VERTEX, label.getAttributeName());
labelSizeArray[labelNum++] = label.getSize();
}
}
use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.
the class GraphVisualAccess method recalculateBottomLabels.
private void recalculateBottomLabels(final ReadableGraph readGraph) {
final GraphLabels bottomLabels = graphBottomLabels != Graph.NOT_FOUND ? readGraph.getObjectValue(graphBottomLabels, 0) : VisualGraphDefaults.DEFAULT_BOTTOM_LABELS;
final int numLabels = bottomLabels.getNumberOfLabels();
bottomLabelAttrs = new int[numLabels];
bottomLabelSizes = new float[numLabels];
bottomLabelColors = new ConstellationColor[numLabels];
int i = 0;
for (final GraphLabel label : bottomLabels.getLabels()) {
bottomLabelAttrs[i] = readGraph.getAttribute(GraphElementType.VERTEX, label.getAttributeName());
bottomLabelSizes[i] = label.getSize();
bottomLabelColors[i] = label.getColor() != null ? label.getColor() : VisualGraphDefaults.DEFAULT_LABEL_COLOR;
i++;
}
}
use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.
the class AbstractGraphLabelsIOProvider method readObject.
/**
* Deserialise an object from a JsonNode.
* <p>
* Refer to base class for detailed description.
*
* @param attributeId The id of the attribute being read.
* @param elementId The id of the element being read.
* @param jnode The JsonNode to read from.
* @param graph The graph that the resulting object will be placed in. Provided in case
* the object requires some graph data.
* @param vertexMap (not used) A mapping from a vertex id in the file to the vertex id
* in the graph.
* @param transactionMap (not used) A mapping from a transaction id in the file to the
* transaction id in the graph.
* @param byteReader (not used) The byte reader containing ancillary data (e.g. images)
* that doesn't easily fit into a JSON document.
* @param (not used) cache A cache that can be used to dedup identical instances of the
* same immutable objects.
* @throws java.io.IOException If there's a problem reading the document.
*/
@Override
public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, ImmutableObjectCache cache) throws IOException {
final List<GraphLabel> labels = new ArrayList<>();
if (!jnode.isNull() && jnode.isArray()) {
for (int i = 0; i < jnode.size(); i++) {
final JsonNode attributeName = jnode.get(i).get(ATTRIBUTE_NAME);
final ConstellationColor colorValue = ColorIOProvider.readColorObject(jnode.get(i).get(COLOR));
final JsonNode radius = jnode.get(i).get(RADIUS);
labels.add(new GraphLabel(attributeName.textValue(), colorValue, radius.floatValue()));
}
graph.setObjectValue(attributeId, elementId, new GraphLabels(labels));
} else {
final String attrVal = jnode.isNull() ? null : jnode.textValue();
graph.setStringValue(attributeId, elementId, attrVal);
}
}
use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.
the class AbstractGraphLabelsIOProvider method writeObject.
@Override
public void writeObject(final Attribute attr, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException {
if (verbose || !graph.isDefaultValue(attr.getId(), elementId)) {
final GraphLabels graphLabels = graph.getObjectValue(attr.getId(), elementId);
if (graphLabels == null) {
jsonGenerator.writeNullField(attr.getName());
} else {
jsonGenerator.writeArrayFieldStart(attr.getName());
for (GraphLabel graphLabel : graphLabels.getLabels()) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField(ATTRIBUTE_NAME, graphLabel.getAttributeName());
final ConstellationColor color = graphLabel.getColor();
jsonGenerator.writeObjectFieldStart(COLOR);
ColorIOProvider.writeColorObject(color, jsonGenerator);
jsonGenerator.writeEndObject();
jsonGenerator.writeNumberField(RADIUS, graphLabel.getSize());
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
}
}
}
use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.
the class VertexGraphLabelsAttributeInteractionNGTest method testGetDisplayText.
/**
* Test of getDisplayText method, of class VertexGraphLabelsAttributeInteraction.
*/
@Test
public void testGetDisplayText() {
System.out.println("getDisplayText");
final VertexGraphLabelsAttributeInteraction instance = new VertexGraphLabelsAttributeInteraction();
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)");
}
Aggregations