use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class ColumnValuesFrequency method getReportHTML.
public String getReportHTML(Table table, Column column, Map<Object, Integer> valuesFrequencies, JFreeChart pieChart, Dimension dimension) {
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
int totalValuesCount = ac.getTableRowsCount(table);
ArrayList<Object> values = new ArrayList<>(valuesFrequencies.keySet());
// Try to sort the values when they are comparable. (All objects of the set will have the same type) and not null:
if (!values.isEmpty() && values.get(0) instanceof Comparable) {
Collections.sort(values, new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
// Check for null objects because some comparables can't handle them (like Float...)
if (o1 == null) {
if (o2 == null) {
return 0;
} else {
// Null lesser than anything
return -1;
}
} else if (o2 == null) {
if (o1 == null) {
return 0;
} else {
// Anything greater than null
return 1;
}
} else {
return ((Comparable) o1).compareTo(o2);
}
}
});
}
final StringBuilder sb = new StringBuilder();
sb.append("<html>");
sb.append(NbBundle.getMessage(ColumnValuesFrequency.class, "ColumnValuesFrequency.report.header", HTMLEscape.stringToHTMLString(column.getTitle())));
sb.append("<hr>");
sb.append("<ol>");
for (Object value : values) {
writeValue(sb, value, valuesFrequencies, totalValuesCount);
}
sb.append("</ol>");
sb.append("<hr>");
if (!values.isEmpty() && values.size() <= MAX_PIE_CHART_CATEGORIES) {
// Do not show pie chart if there are more than 100 different values
try {
if (pieChart != null) {
writePieChart(sb, pieChart, dimension);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
} else {
sb.append(NbBundle.getMessage(ColumnValuesFrequency.class, "ColumnValuesFrequency.report.piechart.not-shown"));
}
sb.append("</html>");
return sb.toString();
}
use of org.gephi.datalab.api.AttributeColumnsController in project gephi-plugins-bootcamp by gephi.
the class ConvertColumnToDynamic method execute.
@Override
public void execute(Table table, Column column) {
Class dynamicType = AttributeUtils.getIntervalMapType(column.getTypeClass());
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
Element[] rows = ac.getTableAttributeRows(table);
Object[] values = new Object[rows.length];
Interval interval = new Interval(Double.parseDouble(start), Double.parseDouble(end));
for (int i = 0; i < values.length; i++) {
try {
IntervalMap val = (IntervalMap) dynamicType.newInstance();
val.put(interval, rows[i].getAttribute(column));
} catch (Exception e) {
}
}
table.removeColumn(column);
Column dynamicColumn = table.addColumn(column.getId(), column.getTitle(), dynamicType, null);
for (int i = 0; i < values.length; i++) {
rows[i].setAttribute(dynamicColumn, values[i]);
}
}
use of org.gephi.datalab.api.AttributeColumnsController in project gephi-plugins-bootcamp by gephi.
the class EqualValuesMergeStrategy method execute.
@Override
public void execute() {
Column column1, column2;
column1 = columns[0];
column2 = columns[1];
// Simplify code using data laboratory API utilities:
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
// New column:
Column newColumn = ac.addAttributeColumn(table, columnTitle, Boolean.class);
// Fill rows of new column:
Element[] rows = ac.getTableAttributeRows(table);
for (int i = 0; i < rows.length; i++) {
rows[i].setAttribute(newColumn, valuesAreEqual(column1, column2, rows[i]));
}
}
use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class ImportCSVUIWizardAction method performAction.
@Override
public void performAction() {
wizardDescriptor = new WizardDescriptor(getPanels());
step1.setWizardDescriptor(wizardDescriptor);
step2.setWizardDescriptor(wizardDescriptor);
// {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
wizardDescriptor.setTitle(getName());
Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
dialog.setVisible(true);
dialog.toFront();
boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
if (!cancelled) {
//General parameters:
File file = (File) wizardDescriptor.getProperty("file");
Character separator = (Character) wizardDescriptor.getProperty("separator");
Charset charset = (Charset) wizardDescriptor.getProperty("charset");
String[] columnNames = (String[]) wizardDescriptor.getProperty("columns-names");
Class[] columnTypes = (Class[]) wizardDescriptor.getProperty("columns-types");
//Nodes import parameters:
Boolean assignNewNodeIds = (Boolean) wizardDescriptor.getProperty("assign-new-node-ids");
//Edges import parameters:
Boolean createNewNodes = (Boolean) wizardDescriptor.getProperty("create-new-nodes");
Graph graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
DataTablesController dtc = Lookup.getDefault().lookup(DataTablesController.class);
dtc.setAutoRefreshEnabled(false);
try {
switch((Mode) wizardDescriptor.getProperty("mode")) {
case NODES_TABLE:
ac.importCSVToNodesTable(graph, file, separator, charset, columnNames, columnTypes, assignNewNodeIds);
break;
case EDGES_TABLE:
ac.importCSVToEdgesTable(graph, file, separator, charset, columnNames, columnTypes, createNewNodes);
break;
}
dtc.refreshCurrentTable();
} catch (Exception e) {
Logger.getLogger("").log(Level.SEVERE, null, e);
} finally {
dtc.setAutoRefreshEnabled(true);
}
}
step1.unSetup();
step2.unSetup();
}
use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class ClearNodesData method setup.
@Override
public void setup(Node[] nodes, Node clickedNode) {
this.nodes = nodes;
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
ArrayList<Column> columnsToClearDataList = new ArrayList<>();
for (Column column : Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable()) {
if (ac.canClearColumnData(column)) {
columnsToClearDataList.add(column);
}
}
columnsToClearData = columnsToClearDataList.toArray(new Column[0]);
}
Aggregations