Search in sources :

Example 1 with GraphLabel

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();
    }
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Example 2 with GraphLabel

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++;
    }
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Example 3 with GraphLabel

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);
    }
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Example 4 with GraphLabel

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();
        }
    }
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Example 5 with GraphLabel

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

Aggregations

GraphLabel (au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)16 GraphLabels (au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels)16 ArrayList (java.util.ArrayList)5 Test (org.testng.annotations.Test)4 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)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 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 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)1 SchemaFactoryUtilities (au.gov.asd.tac.constellation.graph.schema.SchemaFactoryUtilities)1