use of au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators in project constellation by constellation-app.
the class CompleteGraphBuilderPlugin method edit.
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
interaction.setProgress(0, 0, "Building...", true);
final Map<String, PluginParameter<?>> params = parameters.getParameters();
final int n = params.get(N_PARAMETER_ID).getIntegerValue();
final boolean randomWeights = params.get(RANDOM_WEIGHTS_PARAMETER_ID).getBooleanValue();
final List<String> nodeTypes = params.get(NODE_TYPES_PARAMETER_ID).getMultiChoiceValue().getChoices();
final List<String> transactionTypes = params.get(TRANSACTION_TYPES_PARAMETER_ID).getMultiChoiceValue().getChoices();
// Random countries to put in the graph
final List<String> countries = new ArrayList<>();
countries.add("Australia");
countries.add("Brazil");
countries.add("China");
countries.add("France");
countries.add("Japan");
countries.add("New Zealand");
countries.add("South Africa");
countries.add("United Arab Emirates");
countries.add("United Kingdom");
countries.add("United States");
final int vxIdentifierAttr = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
final int vxTypeAttr = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
final int vxIsGoodAttr = graph.addAttribute(GraphElementType.VERTEX, BooleanAttributeDescription.ATTRIBUTE_NAME, "isGood", null, false, null);
final int vxCountryAttr = SpatialConcept.VertexAttribute.COUNTRY.ensure(graph);
final int vxPinnedAttr = VisualConcept.VertexAttribute.PINNED.ensure(graph);
final int txIdAttr = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(graph);
final int txTypeAttr = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
final int txDateTimeAttr = TemporalConcept.TransactionAttribute.DATETIME.ensure(graph);
final VertexDecorators decorators;
decorators = new VertexDecorators(graph.getAttributeName(vxCountryAttr), graph.getAttributeName(vxPinnedAttr), null, graph.getAttributeName(vxIsGoodAttr));
final int decoratorsAttr = VisualConcept.GraphAttribute.DECORATORS.ensure(graph);
graph.setObjectValue(decoratorsAttr, 0, decorators);
final int[] vxIds = new int[n];
int vx = 0;
while (vx < n) {
final int vxId = graph.addVertex();
final String label = "Node_" + vxId;
graph.setStringValue(vxIdentifierAttr, vxId, label);
graph.setStringValue(vxTypeAttr, vxId, nodeTypes.get(r.nextInt(nodeTypes.size())));
graph.setBooleanValue(vxIsGoodAttr, vxId, r.nextInt(10) == 0);
graph.setStringValue(vxCountryAttr, vxId, countries.get(r.nextInt(countries.size())));
if (graph.getSchema() != null) {
graph.getSchema().completeVertex(graph, vxId);
}
vxIds[vx] = vxId;
vx++;
if (Thread.interrupted()) {
throw new InterruptedException();
}
}
// Create transactions between the nodes.
final Date d = new Date();
final int fourDays = 4 * 24 * 60 * 60 * 1000;
for (final int x : vxIds) {
for (final int y : vxIds) {
if (x == y) {
continue;
}
final int reciprocity = r.nextInt(3);
int numTimes = 1;
if (randomWeights) {
numTimes = r.nextInt(1 + r.nextInt(100));
}
for (int i = 0; i < numTimes; i++) {
int sxId = x;
int dxId = y;
if (randomWeights) {
switch(reciprocity) {
case 0:
final boolean random0 = r.nextBoolean();
if (random0) {
sxId = y;
dxId = x;
}
break;
case 1:
final int random1 = r.nextInt(5);
if (random1 == 0) {
sxId = y;
dxId = x;
}
break;
default:
final int randomDefault = r.nextInt(5);
if (randomDefault != 0) {
sxId = y;
dxId = x;
}
break;
}
}
final int e = graph.addTransaction(sxId, dxId, true);
graph.setLongValue(txDateTimeAttr, e, d.getTime() - r.nextInt(fourDays));
graph.setStringValue(txTypeAttr, e, transactionTypes.get(r.nextInt(transactionTypes.size())));
graph.setIntValue(txIdAttr, e, e);
if (graph.getSchema() != null) {
graph.getSchema().completeTransaction(graph, e);
}
if (Thread.interrupted()) {
throw new InterruptedException();
}
}
if (Thread.interrupted()) {
throw new InterruptedException();
}
}
if (Thread.interrupted()) {
throw new InterruptedException();
}
}
try {
if (n < 10000) {
// Do a trees layout.
PluginExecutor.startWith(ArrangementPluginRegistry.TREES).followedBy(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(graph);
} else {
// Do a grid layout.
PluginExecutor.startWith(ArrangementPluginRegistry.GRID_COMPOSITE).followedBy(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(graph);
}
} catch (final PluginException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
interaction.setProgress(1, 0, "Completed successfully", true);
}
use of au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators in project constellation by constellation-app.
the class GraphVisualAccess method recalculateDecorators.
private void recalculateDecorators(final ReadableGraph readGraph) {
final VertexDecorators decorators = graphDecorators != Graph.NOT_FOUND ? readGraph.getObjectValue(graphDecorators, 0) : VisualGraphDefaults.DEFAULT_DECORATORS;
nwDecorator = readGraph.getAttribute(GraphElementType.VERTEX, decorators.getNorthWestDecoratorAttribute());
neDecorator = readGraph.getAttribute(GraphElementType.VERTEX, decorators.getNorthEastDecoratorAttribute());
seDecorator = readGraph.getAttribute(GraphElementType.VERTEX, decorators.getSouthEastDecoratorAttribute());
swDecorator = readGraph.getAttribute(GraphElementType.VERTEX, decorators.getSouthWestDecoratorAttribute());
}
use of au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators in project constellation by constellation-app.
the class DecoratorsIOProvider 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 cache (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 {
if (!jnode.isNull() && jnode.isObject()) {
final String nw = jnode.get(NORTH_WEST).textValue();
final String ne = jnode.get(NORTH_EAST).textValue();
final String se = jnode.get(SOUTH_EAST).textValue();
final String sw = jnode.get(SOUTH_WEST).textValue();
graph.setObjectValue(attributeId, elementId, new VertexDecorators(nw, ne, se, sw));
} else {
final String attributeValue = jnode.isNull() ? null : jnode.textValue();
graph.setStringValue(attributeId, elementId, attributeValue);
}
}
use of au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators 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);
}
}
use of au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators in project constellation by constellation-app.
the class VisualSchemaV5UpdateProvider method schemaUpdate.
@Override
protected void schemaUpdate(final StoreGraph graph) {
final int decoratorsAttribute = VisualConcept.GraphAttribute.DECORATORS.get(graph);
final int pinnedAttribute = VisualConcept.VertexAttribute.PINNED.ensure(graph);
final VertexDecorators oldDecorators = graph.getObjectValue(decoratorsAttribute, 0);
// create the new set of decorators by adding the pinned attribute as the NE decorator and retain all others
final VertexDecorators newDecorators = new VertexDecorators(oldDecorators.getNorthWestDecoratorAttribute(), graph.getAttributeName(pinnedAttribute), oldDecorators.getSouthEastDecoratorAttribute(), oldDecorators.getSouthWestDecoratorAttribute());
graph.setObjectValue(decoratorsAttribute, 0, newDecorators);
}
Aggregations