use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels 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.GraphLabels 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.GraphLabels 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.GraphLabels 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.GraphLabels in project constellation by constellation-app.
the class VisualSchemaV1UpdateProvider method schemaUpdate.
@Override
protected void schemaUpdate(StoreGraph graph) {
final int bottomLabelsAttribute = VisualConcept.GraphAttribute.BOTTOM_LABELS.ensure(graph);
final int decoratorsAttribute = VisualConcept.GraphAttribute.DECORATORS.ensure(graph);
final int topLabelsAttribute = VisualConcept.GraphAttribute.TOP_LABELS.ensure(graph);
final int transactionLabelsAttribute = VisualConcept.GraphAttribute.TRANSACTION_LABELS.ensure(graph);
VisualConcept.GraphAttribute.BLAZE_OPACITY.ensure(graph);
VisualConcept.GraphAttribute.BLAZE_SIZE.ensure(graph);
VisualConcept.GraphAttribute.CONNECTION_MODE.ensure(graph);
VisualConcept.GraphAttribute.DRAW_FLAGS.ensure(graph);
VisualConcept.GraphAttribute.NODE_COLOR_REFERENCE.ensure(graph);
VisualConcept.GraphAttribute.TRANSACTION_COLOR_REFERENCE.ensure(graph);
VisualConcept.GraphAttribute.VISIBLE_ABOVE_THRESHOLD.ensure(graph);
VisualConcept.GraphAttribute.VISIBILITY_THRESHOLD.ensure(graph);
final int labelsAndDecoratorsAttrId = graph.getAttribute(GraphElementType.META, LABELS_AND_DECORATORS_ATTRIBUTE_NAME);
if (labelsAndDecoratorsAttrId != Graph.NOT_FOUND) {
final GraphLabelsAndDecoratorsV0 labelsAndDecorators = graph.getObjectValue(labelsAndDecoratorsAttrId, 0);
if (labelsAndDecorators != null) {
final GraphLabelV0[] bottomLabels = labelsAndDecorators.getBottomLabels();
List<au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel> newBottomLabels = new ArrayList<>();
for (GraphLabelV0 bottomLabel : bottomLabels) {
newBottomLabels.add(new au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel(bottomLabel.getLabel(), bottomLabel.getColor(), bottomLabel.getRadius()));
}
graph.setObjectValue(bottomLabelsAttribute, 0, new GraphLabels(newBottomLabels));
final GraphLabelV0[] topLabels = labelsAndDecorators.getTopLabels();
List<au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel> newTopLabels = new ArrayList<>();
for (GraphLabelV0 topLabel : topLabels) {
newTopLabels.add(new au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel(topLabel.getLabel(), topLabel.getColor(), topLabel.getRadius()));
}
graph.setObjectValue(topLabelsAttribute, 0, new GraphLabels(newTopLabels));
final GraphLabelV0[] connectionLabels = labelsAndDecorators.getConnectionLabels();
List<au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel> newConnectionLabels = new ArrayList<>();
for (GraphLabelV0 connectionLabel : connectionLabels) {
newConnectionLabels.add(new au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel(connectionLabel.getLabel(), connectionLabel.getColor(), connectionLabel.getRadius()));
}
graph.setObjectValue(transactionLabelsAttribute, 0, new GraphLabels(newConnectionLabels));
final String[] decoratorAttributes = labelsAndDecorators.getDecoratorLabels();
graph.setObjectValue(decoratorsAttribute, 0, new VertexDecorators(updateDecoratorAttr(decoratorAttributes[0]), updateDecoratorAttr(decoratorAttributes[1]), updateDecoratorAttr(decoratorAttributes[2]), updateDecoratorAttr(decoratorAttributes[3])));
}
graph.removeAttribute(labelsAndDecoratorsAttrId);
}
final int labelsTopAttrId = graph.getAttribute(GraphElementType.GRAPH, LABELS_TOP_ATTRIBUTE_NAME);
if (labelsTopAttrId != Graph.NOT_FOUND) {
final String[] labelsTop = graph.getStringValue(labelsTopAttrId, 0).split(",");
final List<au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel> newTopLabels = new ArrayList<>();
for (String topLabel : labelsTop) {
newTopLabels.add(new au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel(topLabel, ConstellationColor.LIGHT_BLUE, 1));
}
graph.setObjectValue(topLabelsAttribute, 0, new GraphLabels(newTopLabels));
graph.removeAttribute(labelsTopAttrId);
}
final int labelsBottomAttrId = graph.getAttribute(GraphElementType.GRAPH, LABELS_BOTTOM_ATTRIBUTE_NAME);
if (labelsBottomAttrId != Graph.NOT_FOUND) {
final String[] labelsBottom = graph.getStringValue(labelsBottomAttrId, 0).split(",");
final List<au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel> newBottomLabels = new ArrayList<>();
for (String bottomLabel : labelsBottom) {
newBottomLabels.add(new au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel(bottomLabel, ConstellationColor.LIGHT_BLUE, 1));
}
graph.setObjectValue(bottomLabelsAttribute, 0, new GraphLabels(newBottomLabels));
graph.removeAttribute(labelsBottomAttrId);
}
}
Aggregations