Search in sources :

Example 11 with AttributeColumnsController

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();
}
Also used : AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 12 with AttributeColumnsController

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]);
    }
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) IntervalMap(org.gephi.graph.api.types.IntervalMap) Interval(org.gephi.graph.api.Interval)

Example 13 with AttributeColumnsController

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]));
    }
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element)

Example 14 with AttributeColumnsController

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();
}
Also used : MessageFormat(java.text.MessageFormat) Charset(java.nio.charset.Charset) WizardDescriptor(org.openide.WizardDescriptor) Graph(org.gephi.graph.api.Graph) Dialog(java.awt.Dialog) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) File(java.io.File) DataTablesController(org.gephi.datalab.api.datatables.DataTablesController)

Example 15 with AttributeColumnsController

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]);
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) ArrayList(java.util.ArrayList)

Aggregations

AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)31 Column (org.gephi.graph.api.Column)23 Element (org.gephi.graph.api.Element)14 BigDecimal (java.math.BigDecimal)8 ArrayList (java.util.ArrayList)7 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)5 Edge (org.gephi.graph.api.Edge)3 PropertyEditor (java.beans.PropertyEditor)2 Node (org.gephi.graph.api.Node)2 TimeFormat (org.gephi.graph.api.TimeFormat)2 IntervalSet (org.gephi.graph.api.types.IntervalSet)2 AttributeValueWrapper (org.gephi.ui.tools.plugin.edit.EditWindowUtils.AttributeValueWrapper)2 DateTimeZone (org.joda.time.DateTimeZone)2 PropertySupport (org.openide.nodes.PropertySupport)2 Sheet (org.openide.nodes.Sheet)2 CsvWriter (com.csvreader.CsvWriter)1 Dialog (java.awt.Dialog)1 File (java.io.File)1 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1