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;
}
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;
}
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);
}
}
}
}
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;
}
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;
}
Aggregations