Search in sources :

Example 11 with CyColumnIdentifier

use of org.cytoscape.view.presentation.property.values.CyColumnIdentifier in project EnrichmentMapApp by BaderLab.

the class AbstractChart method getDataFromColumns.

public Map<String, List<Double>> getDataFromColumns(final CyNetwork network, final CyIdentifiable model, final List<CyColumnIdentifier> columnNames) {
    LinkedHashMap<String, List<Double>> data = new LinkedHashMap<>();
    final CyRow row = network.getRow(model);
    if (row == null)
        return data;
    final CyTable table = row.getTable();
    final List<Double> singleSeriesValues = new ArrayList<>();
    final StringBuilder singleSeriesKey = new StringBuilder();
    int singleSeriesIndex = -1;
    int count = 0;
    for (final CyColumnIdentifier colId : columnNames) {
        final CyColumn column = table.getColumn(colId.getColumnName());
        if (column == null)
            continue;
        final String colName = column.getName();
        final List<Double> values = new ArrayList<>();
        if (column.getType() == List.class) {
            // List Column: One column = one data series
            final Class<?> type = column.getListElementType();
            if (type == Double.class) {
                List<Double> list = row.getList(colName, Double.class);
                if (list != null)
                    values.addAll(list);
            } else if (type == Integer.class) {
                List<Integer> list = row.getList(colName, Integer.class);
                if (list != null) {
                    for (Integer i : list) values.add(i.doubleValue());
                }
            } else if (type == Long.class) {
                List<Long> list = row.getList(colName, Long.class);
                if (list != null) {
                    for (Long l : list) values.add(l.doubleValue());
                }
            } else if (type == Float.class) {
                List<Float> list = row.getList(colName, Float.class);
                if (list != null) {
                    for (Float f : list) values.add(f.doubleValue());
                }
            }
            data.put(colName, values);
        } else {
            // Single Column: All single columns together make only one data series
            final Class<?> type = column.getType();
            if (Number.class.isAssignableFrom(type)) {
                if (!row.isSet(colName)) {
                    singleSeriesValues.add(Double.NaN);
                } else if (type == Double.class) {
                    singleSeriesValues.add(row.get(colName, Double.class));
                } else if (type == Integer.class) {
                    Integer i = row.get(colName, Integer.class);
                    singleSeriesValues.add(i.doubleValue());
                } else if (type == Float.class) {
                    Float f = row.get(colName, Float.class);
                    singleSeriesValues.add(f.doubleValue());
                }
                singleSeriesKey.append(colName + ",");
                // The index of this data series is the index of the first single column
                if (singleSeriesIndex == -1)
                    singleSeriesIndex = count;
            }
        }
        count++;
    }
    if (!singleSeriesValues.isEmpty()) {
        singleSeriesKey.deleteCharAt(singleSeriesKey.length() - 1);
        // To add the series of single columns into the correct position, we have to rebuild the data map
        final Set<Entry<String, List<Double>>> entrySet = data.entrySet();
        data = new LinkedHashMap<>();
        int i = 0;
        for (final Entry<String, List<Double>> entry : entrySet) {
            if (i == singleSeriesIndex)
                data.put(singleSeriesKey.toString(), singleSeriesValues);
            data.put(entry.getKey(), entry.getValue());
            i++;
        }
        if (// (entrySet.isEmpty() || i >= entrySet.size())
        !data.containsKey(singleSeriesKey.toString()))
            data.put(singleSeriesKey.toString(), singleSeriesValues);
    }
    return data;
}
Also used : ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) CyRow(org.cytoscape.model.CyRow) LinkedHashMap(java.util.LinkedHashMap) CyTable(org.cytoscape.model.CyTable) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with CyColumnIdentifier

use of org.cytoscape.view.presentation.property.values.CyColumnIdentifier in project EnrichmentMapApp by BaderLab.

the class AbstractChart method getItemLabels.

protected List<String> getItemLabels(final CyNetwork network, final CyIdentifiable model) {
    List<String> labels = getList(ITEM_LABELS, String.class);
    if (labels == null || labels.isEmpty()) {
        final CyColumnIdentifier labelsColumn = get(ITEM_LABELS_COLUMN, CyColumnIdentifier.class);
        labels = getLabelsFromColumn(network, model, labelsColumn);
    }
    return labels;
}
Also used : CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier)

Example 13 with CyColumnIdentifier

use of org.cytoscape.view.presentation.property.values.CyColumnIdentifier in project cytoscape-impl by cytoscape.

the class NetworkViewMediator method handleEvent.

@Override
public void handleEvent(final ViewChangedEvent<?> e) {
    final CyNetworkView netView = e.getSource();
    // Ask the Views Panel to update the thumbnail for the affected network view
    invokeOnEDT(() -> {
        if (!getNetworkViewMainPanel().isGridVisible()) {
            getNetworkViewMainPanel().update(netView);
        }
    });
    // Look for MappableVisualPropertyValue objects, so they can be saved for future reference
    for (final ViewChangeRecord<?> record : e.getPayloadCollection()) {
        if (!record.isLockedValue())
            continue;
        final View<?> view = record.getView();
        final Object value = record.getValue();
        if (value instanceof MappableVisualPropertyValue) {
            final Set<CyColumnIdentifier> columnIds = ((MappableVisualPropertyValue) value).getMappedColumns();
            if (columnIds == null)
                continue;
            final VisualProperty<?> vp = record.getVisualProperty();
            for (final CyColumnIdentifier colId : columnIds) {
                Map<MappedVisualPropertyValueInfo, Set<View<?>>> mvpInfoMap = mappedValuesMap.get(colId);
                if (mvpInfoMap == null)
                    mappedValuesMap.put(colId, mvpInfoMap = new HashMap<>());
                final MappedVisualPropertyValueInfo mvpInfo = new MappedVisualPropertyValueInfo((MappableVisualPropertyValue) value, vp, netView);
                Set<View<?>> viewSet = mvpInfoMap.get(mvpInfo);
                if (viewSet == null)
                    mvpInfoMap.put(mvpInfo, viewSet = new HashSet<View<?>>());
                viewSet.add(view);
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) MappableVisualPropertyValue(org.cytoscape.view.presentation.property.values.MappableVisualPropertyValue) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 14 with CyColumnIdentifier

use of org.cytoscape.view.presentation.property.values.CyColumnIdentifier in project cytoscape-impl by cytoscape.

the class NetworkViewMediator method reapplyLockedValues.

@SuppressWarnings({ "rawtypes", "unchecked" })
private boolean reapplyLockedValues(final String columnName, final Collection<CyNetworkView> networkViews) {
    boolean result = false;
    final CyColumnIdentifierFactory colIdfFactory = serviceRegistrar.getService(CyColumnIdentifierFactory.class);
    final CyColumnIdentifier colId = colIdfFactory.createColumnIdentifier(columnName);
    final Map<MappedVisualPropertyValueInfo, Set<View<?>>> mvpInfoMap = mappedValuesMap.get(colId);
    if (mvpInfoMap != null) {
        for (final MappedVisualPropertyValueInfo mvpInfo : mvpInfoMap.keySet()) {
            if (networkViews == null || !networkViews.contains(mvpInfo.getNetworkView()))
                continue;
            final MappableVisualPropertyValue value = mvpInfo.getValue();
            final VisualProperty vp = mvpInfo.getVisualProperty();
            final Set<View<?>> viewSet = mvpInfoMap.get(mvpInfo);
            for (final View<?> view : viewSet) {
                if (view.isDirectlyLocked(vp) && value.equals(view.getVisualProperty(vp))) {
                    value.update();
                    view.setLockedValue(vp, value);
                    result = true;
                }
            }
        }
    }
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) MappableVisualPropertyValue(org.cytoscape.view.presentation.property.values.MappableVisualPropertyValue) CyColumnIdentifierFactory(org.cytoscape.view.presentation.property.values.CyColumnIdentifierFactory) VisualProperty(org.cytoscape.view.model.VisualProperty) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 15 with CyColumnIdentifier

use of org.cytoscape.view.presentation.property.values.CyColumnIdentifier in project cytoscape-impl by cytoscape.

the class AbstractChart method getSingleValueColumnNames.

/**
 * @return The names of the data columns or an empty list if any of the data columns is of type List.
 */
protected List<String> getSingleValueColumnNames(final CyNetwork network, final CyIdentifiable model) {
    final List<String> names = new ArrayList<>();
    final CyRow row = network.getRow(model);
    if (row == null)
        return names;
    final List<CyColumnIdentifier> dataColumns = getList(DATA_COLUMNS, CyColumnIdentifier.class);
    final CyTable table = row.getTable();
    boolean invalid = false;
    for (final CyColumnIdentifier colId : dataColumns) {
        final CyColumn column = table.getColumn(colId.getColumnName());
        if (column == null || column.getType() == List.class) {
            // Not a single value column!
            invalid = true;
            break;
        }
        names.add(colId.getColumnName());
    }
    if (invalid)
        names.clear();
    return names;
}
Also used : CyTable(org.cytoscape.model.CyTable) ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn) ArrayList(java.util.ArrayList) List(java.util.List) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) CyRow(org.cytoscape.model.CyRow)

Aggregations

CyColumnIdentifier (org.cytoscape.view.presentation.property.values.CyColumnIdentifier)21 Color (java.awt.Color)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 CyColumn (org.cytoscape.model.CyColumn)6 CyRow (org.cytoscape.model.CyRow)6 AbstractCustomGraphics2Test (org.cytoscape.ding.customgraphics.AbstractCustomGraphics2Test)5 ColorScheme (org.cytoscape.ding.customgraphics.ColorScheme)5 CyTable (org.cytoscape.model.CyTable)4 Test (org.junit.Test)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 Orientation (org.cytoscape.ding.customgraphics.Orientation)3 MappableVisualPropertyValue (org.cytoscape.view.presentation.property.values.MappableVisualPropertyValue)3 Collator (java.text.Collator)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2