use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class ArrangeByNodeAttributePlugin method edit.
@Override
public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final boolean threeD = parameters.getParameters().get(THREE_D_PARAMETER_ID).getBooleanValue();
final String attribute = parameters.getParameters().get(ATTRIBUTE_PARAMETER_ID).getStringValue();
if (threeD) {
if (attribute != null) {
final SelectedInclusionGraph selectedGraph = new SelectedInclusionGraph(wg, SelectedInclusionGraph.Connections.NONE);
final Attribute attr = new GraphAttribute(wg, wg.getAttribute(GraphElementType.VERTEX, attribute));
selectedGraph.addAttributeToCopy(attr);
final GraphWriteMethods ig = selectedGraph.getInclusionGraph();
final int iattrId = ig.getAttribute(GraphElementType.VERTEX, attribute);
final LayerArranger arranger = new LayerArranger();
arranger.setLevelAttr(iattrId);
arranger.setMaintainMean(!selectedGraph.isArrangingAll());
arranger.arrange(ig);
selectedGraph.retrieveCoords();
}
} else {
if (attribute != null) {
final Arranger inner = new GridArranger();
final Arranger outer = new GridArranger();
final GraphTaxonomyArranger arranger = new ArrangeByGroupTaxonomy(inner, outer, Connections.NONE, attribute);
arranger.setMaintainMean(true);
final SelectedInclusionGraph selectedGraph = new SelectedInclusionGraph(wg, Connections.NONE);
selectedGraph.addAttributeToCopy(new GraphAttribute(wg, wg.getAttribute(GraphElementType.VERTEX, attribute)));
arranger.arrange(selectedGraph.getInclusionGraph());
selectedGraph.retrieveCoords();
}
}
}
use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class LayerByTimePlugin method read.
@Override
public void read(final GraphReadMethods rg, final PluginInteraction interaction, final PluginParameters parameters) throws PluginException, InterruptedException {
// We have the dtAttr from the original wg: we should have been passed the label, but never mind.
// We need to get the label from the original, so we can get the dtAttr for the copy.
final String dtAttrOrig = parameters.getParameters().get(DATETIME_ATTRIBUTE_PARAMETER_ID).getStringValue();
if (dtAttrOrig == null) {
interaction.notify(PluginNotificationLevel.ERROR, "A date-time attribute must be specified.");
return;
}
final int dtAttrOrigId = rg.getAttribute(GraphElementType.TRANSACTION, dtAttrOrig);
if (dtAttrOrigId == Graph.NOT_FOUND) {
interaction.notify(PluginNotificationLevel.ERROR, "A valid date-time attribute must be specified.");
return;
}
Graph copy;
try {
final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
final PluginParameters copyParams = copyGraphPlugin.createParameters();
copyParams.getParameters().get(CopyToNewGraphPlugin.NEW_SCHEMA_NAME_PARAMETER_ID).setStringValue(rg.getSchema().getFactory().getName());
copyParams.getParameters().get(CopyToNewGraphPlugin.COPY_ALL_PARAMETER_ID).setBooleanValue(true);
copyParams.getParameters().get(CopyToNewGraphPlugin.COPY_KEYS_PARAMETER_ID).setBooleanValue(false);
PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyParams).executeNow(rg);
copy = (Graph) copyParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
} catch (final PluginException ex) {
copy = null;
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
if (copy == null) {
// The copy failed, drop out now.
return;
}
final Attribute dt = new GraphAttribute(rg, dtAttrOrigId);
final WritableGraph wgcopy = copy.getWritableGraph("Layer by time", true);
try {
final int dtAttr = wgcopy.getAttribute(GraphElementType.TRANSACTION, dt.getName());
final boolean useIntervals = parameters.getParameters().get(LAYER_BY_PARAMETER_ID).getStringValue().equals(INTERVAL_METHOD);
final ZonedDateTime[] startEnd = parameters.getParameters().get(DATE_RANGE_PARAMETER_ID).getDateTimeRangeValue().getZonedStartEnd();
final ZonedDateTime start = startEnd[0];
final ZonedDateTime end = startEnd[1];
final boolean isTransactionLayers = parameters.getParameters().get(TRANSACTION_AS_LAYER_PARAMETER_ID).getBooleanValue();
// Establish new attributes.
// Create and store graph attributes.
final LayerName defaultName = new LayerName(Graph.NOT_FOUND, "Default");
final int timeLayerAttr = wgcopy.addAttribute(GraphElementType.TRANSACTION, LayerNameAttributeDescription.ATTRIBUTE_NAME, LAYER_NAME, "time layer", defaultName, null);
wgcopy.addAttribute(GraphElementType.GRAPH, IntegerAttributeDescription.ATTRIBUTE_NAME, NLAYERS, "The number of layers to layer by time", 1, null);
final int txColorAttr = wgcopy.getAttribute(GraphElementType.TRANSACTION, "color");
final int txGuideline = wgcopy.addAttribute(GraphElementType.TRANSACTION, BooleanAttributeDescription.ATTRIBUTE_NAME, "layer_guideline", "This transaction is a layer guideline", false, null);
final ConstellationColor guidelineColor = ConstellationColor.getColorValue(0.25F, 0.25F, 0.25F, 1F);
wgcopy.addAttribute(GraphElementType.VERTEX, IntegerAttributeDescription.ATTRIBUTE_NAME, ORIGINAL_ID_LABEL, "Original Node Id", -1, null);
final List<Float> values = new ArrayList<>();
final Map<Integer, List<Float>> remappedLayers = new HashMap<>();
final Map<Integer, String> displayNames = new HashMap<>();
if (useIntervals) {
final int intervalUnit = LAYER_INTERVALS.get(parameters.getParameters().get(UNIT_PARAMETER_ID).getStringValue());
final int intervalAmount = parameters.getParameters().get(AMOUNT_PARAMETER_ID).getIntegerValue();
buildIntervals(wgcopy, values, remappedLayers, displayNames, dtAttr, start.toInstant(), end.toInstant(), intervalUnit, intervalAmount);
} else {
final int calendarUnit = BIN_CALENDAR_UNITS.get(parameters.getParameters().get(UNIT_PARAMETER_ID).getStringValue());
final int binAmount = parameters.getParameters().get(AMOUNT_PARAMETER_ID).getIntegerValue();
buildBins(wgcopy, values, remappedLayers, displayNames, dtAttr, start.toInstant(), end.toInstant(), calendarUnit, binAmount);
}
final boolean keepTxColors = parameters.getParameters().get(KEEP_TX_COLORS_PARAMETER_ID).getBooleanValue();
final boolean drawTxGuides = parameters.getParameters().get(DRAW_TX_GUIDES_PARAMETER_ID).getBooleanValue();
// Modify the copied graph to show our layers.
int z = 0;
float step = getWidth(wgcopy) / values.size();
for (final Entry<Integer, List<Float>> entry : remappedLayers.entrySet()) {
for (final Entry<Float, List<Integer>> currentLayer : transactionLayers.entrySet()) {
if (entry.getValue().contains(currentLayer.getKey())) {
for (final int txId : currentLayer.getValue()) {
final float origLayer = currentLayer.getKey();
int newLayer = 0;
if (entry.getValue().contains(origLayer)) {
// Overwrite value
newLayer = entry.getKey();
}
final LayerName dn = new LayerName(newLayer, displayNames.get(newLayer));
wgcopy.setObjectValue(timeLayerAttr, txId, dn);
final float normLayer = newLayer / (remappedLayers.keySet().size() * 1F);
if (!keepTxColors) {
final Color heatmap = new Color(Color.HSBtoRGB((1 - normLayer) * 2F / 3F, 0.5F, 1));
final ConstellationColor color = ConstellationColor.getColorValue(heatmap.getRed() / 255F, heatmap.getGreen() / 255F, heatmap.getBlue() / 255F, 1F);
wgcopy.setObjectValue(txColorAttr, txId, color);
}
if (isTransactionLayers) {
transactionsAsLayers(wgcopy, txId, z, step);
} else {
nodesAsLayers(wgcopy, txId, newLayer);
}
}
}
}
if (isTransactionLayers) {
srcVxMap = dstVxMap;
dstVxMap = new HashMap<>();
z += step;
}
}
// Remove any outstanding transactions flagged for deletion
for (int txId = txToDelete.nextSetBit(0); txId >= 0; txId = txToDelete.nextSetBit(txId + 1)) {
wgcopy.removeTransaction(txId);
}
// Get rid of all of the nodes that don't have any transactions.
// By definition, the duplicates will have transactions between them, including the original layer
// (because we just deleted transactions that belong in different layers, leaving only the transactions
// that belong in the original layer).
final List<Integer> vertices = new ArrayList<>();
for (int position = 0; position < wgcopy.getVertexCount(); position++) {
final int vertexId = wgcopy.getVertex(position);
final int nTx = wgcopy.getVertexTransactionCount(vertexId);
if (nTx == 0) {
vertices.add(vertexId);
}
}
vertices.stream().forEach(wgcopy::removeVertex);
if (drawTxGuides) {
interaction.setProgress(5, 6, "Draw guide lines", false);
// We have to do this after the "remove node without transactions" step because we're adding more transactions.
if (!isTransactionLayers && remappedLayers.keySet().size() > 1) {
nodeIdToLayers.keySet().stream().forEach(origNodeId -> {
int prevNodeId = -1;
final BitSet layers = nodeIdToLayers.get(origNodeId);
for (int layer = layers.nextSetBit(0); layer >= 0; layer = layers.nextSetBit(layer + 1)) {
final int nodeId = layer == 0 ? origNodeId : nodeDups.get(String.format("%s/%s", origNodeId, layer));
if (prevNodeId != -1) {
final int sTxId = wgcopy.addTransaction(prevNodeId, nodeId, false);
wgcopy.setBooleanValue(txGuideline, sTxId, true);
wgcopy.setObjectValue(txColorAttr, sTxId, guidelineColor);
final LayerName dn = new LayerName(1107, "Guideline");
wgcopy.setObjectValue(timeLayerAttr, sTxId, dn);
}
prevNodeId = nodeId;
}
});
}
}
} finally {
wgcopy.commit();
}
}
use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class LayerByTimePlugin method updateParameters.
@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
final ReadableGraph rg = graph.getReadableGraph();
final List<String> dateTimeAttributes = new ArrayList<>();
try {
final int attributeCount = rg.getAttributeCount(GraphElementType.TRANSACTION);
for (int i = 0; i < attributeCount; i++) {
final int attrId = rg.getAttribute(GraphElementType.TRANSACTION, i);
final Attribute attr = new GraphAttribute(rg, attrId);
if (attr.getAttributeType().equals(ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME)) {
dateTimeAttributes.add(attr.getName());
}
}
} finally {
rg.release();
}
SingleChoiceParameterType.setOptions(dtAttrParam, dateTimeAttributes);
parameters.addController(DATETIME_ATTRIBUTE_PARAMETER_ID, (masterId, paramMap, change) -> {
if (change == ParameterChange.VALUE) {
final String attrName = paramMap.get(DATETIME_ATTRIBUTE_PARAMETER_ID).getStringValue();
final ReadableGraph rg2 = graph.getReadableGraph();
try {
final int attrId = rg2.getAttribute(GraphElementType.TRANSACTION, attrName);
if (attrId == Graph.NOT_FOUND) {
return;
}
ZonedDateTime min = ZonedDateTime.ofInstant(Instant.now(), TimeZoneUtilities.UTC);
ZonedDateTime max = ZonedDateTime.ofInstant(Instant.EPOCH, TimeZoneUtilities.UTC);
final int txCount = rg.getTransactionCount();
boolean nonNullDateTimeFound = false;
for (int position = 0; position < txCount; position++) {
final int txId = rg.getTransaction(position);
// Ignore zero and "null" dates.
final ZonedDateTime dt = rg.getObjectValue(attrId, txId);
if (dt != null) {
nonNullDateTimeFound = true;
if (dt.toInstant().isBefore(min.toInstant())) {
min = dt;
}
if (dt.toInstant().isAfter(max.toInstant())) {
max = dt;
}
}
}
if (!nonNullDateTimeFound) {
final ZonedDateTime swap = min;
min = max;
max = swap;
}
dateRangeParam.setDateTimeRangeValue(new DateTimeRange(min, max));
} finally {
rg2.release();
}
}
});
}
use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class ArrangeInScatter3dGeneralPlugin method edit.
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final SetRadiusForArrangement radiusSetter = new SetRadiusForArrangement(graph);
radiusSetter.setRadii();
final Map<String, PluginParameter<?>> pp = parameters.getParameters();
final Scatter3dChoiceParameters scatter3dParams = Scatter3dChoiceParameters.getDefaultParameters();
final String xDimensionName = pp.get(SCATTER_3D_X_ATTRIBUTE).getStringValue();
final String yDimensionName = pp.get(SCATTER_3D_Y_ATTRIBUTE).getStringValue();
final String zDimensionName = pp.get(SCATTER_3D_Z_ATTRIBUTE).getStringValue();
if (StringUtils.isAnyBlank(new String[] { xDimensionName, yDimensionName, zDimensionName })) {
interaction.notify(PluginNotificationLevel.FATAL, "You must supply all 3 attribute names for Scatter 3D");
return;
}
scatter3dParams.setXDimension(xDimensionName);
scatter3dParams.setYDimension(yDimensionName);
scatter3dParams.setZDimension(zDimensionName);
scatter3dParams.setLogarithmicX(pp.get(SCATTER_3D_X_LOGARITHMIC).getBooleanValue());
scatter3dParams.setLogarithmicY(pp.get(SCATTER_3D_Y_LOGARITHMIC).getBooleanValue());
scatter3dParams.setLogarithmicZ(pp.get(SCATTER_3D_Z_LOGARITHMIC).getBooleanValue());
scatter3dParams.setDoNotScale(pp.get(SCATTER_3D_DO_NOT_SCALE).getBooleanValue());
final SelectedInclusionGraph selectedGraph = new SelectedInclusionGraph(graph, SelectedInclusionGraph.Connections.NONE);
selectedGraph.addAttributeToCopy(new GraphAttribute(graph, graph.getAttribute(GraphElementType.VERTEX, xDimensionName)));
selectedGraph.addAttributeToCopy(new GraphAttribute(graph, graph.getAttribute(GraphElementType.VERTEX, yDimensionName)));
selectedGraph.addAttributeToCopy(new GraphAttribute(graph, graph.getAttribute(GraphElementType.VERTEX, zDimensionName)));
final Scatter3dArranger arranger = new Scatter3dArranger(scatter3dParams);
arranger.arrange(selectedGraph.getInclusionGraph());
selectedGraph.retrieveCoords();
}
use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class FindTopComponent method setDefaultFindCriteriaPanels.
/**
* add set of find criteria panel based on primary keys, otherwise just add
* one with the first column in it
*/
private void setDefaultFindCriteriaPanels() {
final Graph graph = graphNode.getGraph();
ReadableGraph rg = graph.getReadableGraph();
try {
int[] keys = rg.getPrimaryKey(type);
if (keys.length == 0) {
addFindCriteriaPanel();
} else {
for (int i = 0; i < keys.length; i++) {
Attribute attr = new GraphAttribute(rg, keys[i]);
FindRule rule = new FindRule();
rule.setAttribute(attr);
if ("boolean".equalsIgnoreCase(attr.getAttributeType())) {
rule.addBooleanBasedRule(true);
rule.setOperator(FindTypeOperators.Operator.IS);
} else if ("color".equalsIgnoreCase(attr.getAttributeType())) {
rule.addColorBasedRule(Color.BLACK);
rule.setOperator(FindTypeOperators.Operator.IS);
} else if ("date".equalsIgnoreCase(attr.getAttributeType())) {
rule.addDateBasedRule(new Date(), new Date());
rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
} else if (attr.getAttributeType().equalsIgnoreCase(ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME)) {
rule.addDateTimeBasedRule(new GregorianCalendar(), new GregorianCalendar());
rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
} else if ("time".equalsIgnoreCase(attr.getAttributeType())) {
rule.addTimeBasedRule(new GregorianCalendar(), new GregorianCalendar());
rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
} else if ("float".equalsIgnoreCase(attr.getAttributeType())) {
rule.addFloatBasedRule(0.0F, 0.0F);
rule.setOperator(FindTypeOperators.Operator.IS);
} else if ("integer".equalsIgnoreCase(attr.getAttributeType())) {
rule.addIntegerBasedRule(0, 0);
rule.setOperator(FindTypeOperators.Operator.IS);
} else if ("icon".equalsIgnoreCase(attr.getAttributeType())) {
rule.addIconBasedRule("");
rule.setOperator(FindTypeOperators.Operator.IS);
} else {
// string
rule.addStringBasedRule("", false, false);
rule.setOperator(FindTypeOperators.Operator.CONTAINS);
}
addFindCriteriaPanel(rule);
}
}
} finally {
rg.release();
}
}
Aggregations