Search in sources :

Example 16 with CyColumnIdentifier

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

the class AbstractChartEditor method calculateAutoRange.

@SuppressWarnings("unchecked")
protected List<Double> calculateAutoRange() {
    final List<Double> range = new ArrayList<>(2);
    final CyNetwork net = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
    if (net != null) {
        final List<CyNode> nodes = net.getNodeList();
        final List<CyColumnIdentifier> dataColumns = getDataPnl().getDataColumns();
        double min = Double.POSITIVE_INFINITY;
        double max = Double.NEGATIVE_INFINITY;
        for (final CyColumnIdentifier colId : dataColumns) {
            final CyColumn column = columns.get(colId);
            if (column == null)
                continue;
            final Class<?> colType = column.getType();
            final Class<?> colListType = column.getListElementType();
            if (Number.class.isAssignableFrom(colType) || (List.class.isAssignableFrom(colType) && Number.class.isAssignableFrom(colListType))) {
                for (final CyNode n : nodes) {
                    List<? extends Number> values = null;
                    final CyRow row = net.getRow(n);
                    if (List.class.isAssignableFrom(colType))
                        values = (List<? extends Number>) row.getList(column.getName(), colListType);
                    else if (row.isSet(column.getName()))
                        values = Collections.singletonList((Number) row.get(column.getName(), colType));
                    double[] mm = minMax(min, max, values);
                    min = mm[0];
                    max = mm[1];
                }
            }
        }
        if (min != Double.POSITIVE_INFINITY && max != Double.NEGATIVE_INFINITY) {
            range.add(min);
            range.add(max);
        }
    }
    return range;
}
Also used : ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) CyRow(org.cytoscape.model.CyRow) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNode(org.cytoscape.model.CyNode) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) JList(javax.swing.JList)

Example 17 with CyColumnIdentifier

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

the class AbstractChartEditor method getRangeLabelsColumnCmb.

protected JComboBox<CyColumnIdentifier> getRangeLabelsColumnCmb() {
    if (rangeLabelsColumnCmb == null) {
        rangeLabelsColumnCmb = new CyColumnComboBox(labelColumns.keySet(), true);
        selectColumnIdItem(rangeLabelsColumnCmb, chart.get(RANGE_LABELS_COLUMN, CyColumnIdentifier.class));
        rangeLabelsColumnCmb.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                final CyColumnIdentifier colId = (CyColumnIdentifier) rangeLabelsColumnCmb.getSelectedItem();
                chart.set(RANGE_LABELS_COLUMN, colId != null ? colId.getColumnName() : null);
            }
        });
    }
    return rangeLabelsColumnCmb;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier)

Example 18 with CyColumnIdentifier

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

the class BarChartTest method testChartProperties.

@Test
public void testChartProperties() {
    final BarChart chart = new BarChart(props1, serviceRegistrar);
    // The chart properties has to return exactly the same values,
    // except column names, which are converted to CyColumIdentifier when set as String
    Map<String, Object> props2 = chart.getProperties();
    assertEquals(props1.get(DATA_COLUMNS), props2.get(DATA_COLUMNS));
    assertEquals(props1.get(COLOR_SCHEME), props2.get(COLOR_SCHEME));
    assertEquals(props1.get(TYPE), props2.get(TYPE));
    assertEquals(props1.get(SEPARATION), props2.get(SEPARATION));
    assertEquals(props1.get(AUTO_RANGE), props2.get(AUTO_RANGE));
    assertEquals(props1.get(GLOBAL_RANGE), props2.get(GLOBAL_RANGE));
    assertEquals(props1.get(RANGE), props2.get(RANGE));
    assertEquals(props1.get(COLORS), props2.get(COLORS));
    assertEquals(props1.get(ORIENTATION), props2.get(ORIENTATION));
    assertEquals(props1.get(BORDER_COLOR), props2.get(BORDER_COLOR));
    assertEquals(props1.get(BORDER_WIDTH), props2.get(BORDER_WIDTH));
    assertEquals("labels1", ((CyColumnIdentifier) props2.get(ITEM_LABELS_COLUMN)).getColumnName());
    assertEquals("labels2", ((CyColumnIdentifier) props2.get(DOMAIN_LABELS_COLUMN)).getColumnName());
    assertEquals("labels3", ((CyColumnIdentifier) props2.get(RANGE_LABELS_COLUMN)).getColumnName());
    assertEquals(props1.get(DOMAIN_LABEL_POSITION), props2.get(DOMAIN_LABEL_POSITION));
    assertEquals(props1.get(ITEM_LABELS), props2.get(ITEM_LABELS));
    assertEquals(props1.get(SHOW_ITEM_LABELS), props2.get(SHOW_ITEM_LABELS));
    assertEquals(props1.get(SHOW_DOMAIN_AXIS), props2.get(SHOW_DOMAIN_AXIS));
    assertEquals(props1.get(SHOW_RANGE_AXIS), props2.get(SHOW_RANGE_AXIS));
    assertEquals(props1.get(SHOW_RANGE_ZERO_BASELINE), props2.get(SHOW_RANGE_ZERO_BASELINE));
    assertEquals(props1.get(AXIS_WIDTH), props2.get(AXIS_WIDTH));
    assertEquals(props1.get(AXIS_COLOR), props2.get(AXIS_COLOR));
    assertNull(props2.get(VALUES));
    // When calling the internal get methods, some property values are converted to internal types,
    // which are not exposed to the API client code
    assertEquals(props2.get(DATA_COLUMNS), chart.getList(DATA_COLUMNS, CyColumnIdentifier.class));
    assertEquals(ColorScheme.RAINBOW, chart.get(COLOR_SCHEME, ColorScheme.class));
    assertEquals(BarChartType.HEAT_STRIPS, chart.get(TYPE, BarChartType.class));
    assertEquals(new Double(0.2), chart.get(SEPARATION, Double.class));
    assertEquals(Boolean.FALSE, chart.get(AUTO_RANGE, Boolean.class));
    assertEquals(Boolean.TRUE, chart.get(GLOBAL_RANGE, Boolean.class));
    assertEquals(props1.get(RANGE), chart.getList(RANGE, Double.class));
    assertEquals(props1.get(COLORS), chart.getList(COLORS, Color.class));
    assertEquals(Orientation.VERTICAL, chart.get(ORIENTATION, Orientation.class));
    assertEquals(Color.WHITE, chart.get(BORDER_COLOR, Color.class));
    assertEquals(new Float(2.5f), chart.get(BORDER_WIDTH, Float.class));
    assertEquals("labels1", chart.get(ITEM_LABELS_COLUMN, CyColumnIdentifier.class).getColumnName());
    assertEquals("labels2", chart.get(DOMAIN_LABELS_COLUMN, CyColumnIdentifier.class).getColumnName());
    assertEquals("labels3", chart.get(RANGE_LABELS_COLUMN, CyColumnIdentifier.class).getColumnName());
    assertEquals(LabelPosition.UP_45, chart.get(DOMAIN_LABEL_POSITION, LabelPosition.class));
    assertEquals(props1.get(ITEM_LABELS), chart.getList(ITEM_LABELS, String.class));
    assertEquals(Boolean.TRUE, chart.get(SHOW_ITEM_LABELS, Boolean.class));
    assertEquals(Boolean.TRUE, chart.get(SHOW_DOMAIN_AXIS, Boolean.class));
    assertEquals(Boolean.FALSE, chart.get(SHOW_RANGE_AXIS, Boolean.class));
    assertEquals(Boolean.TRUE, chart.get(SHOW_RANGE_ZERO_BASELINE, Boolean.class));
    assertEquals(new Float(1.5f), chart.get(AXIS_WIDTH, Float.class));
    assertEquals(Color.YELLOW, chart.get(AXIS_COLOR, Color.class));
    // Must never be null!
    assertTrue(chart.getList(VALUES, Double.class).isEmpty());
}
Also used : Color(java.awt.Color) ColorScheme(org.cytoscape.ding.customgraphics.ColorScheme) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) Orientation(org.cytoscape.ding.customgraphics.Orientation) BarChart(org.cytoscape.ding.internal.charts.bar.BarChart) BarChartType(org.cytoscape.ding.internal.charts.bar.BarChart.BarChartType) AbstractCustomGraphics2Test(org.cytoscape.ding.customgraphics.AbstractCustomGraphics2Test) Test(org.junit.Test)

Example 19 with CyColumnIdentifier

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

the class LineChartTest method testChartProperties.

@Test
public void testChartProperties() {
    final LineChart chart = new LineChart(props1, serviceRegistrar);
    // The chart properties has to return exactly the same values,
    // except column names, which are converted to CyColumIdentifier when set as String
    Map<String, Object> props2 = chart.getProperties();
    assertEquals(props1.get(DATA_COLUMNS), props2.get(DATA_COLUMNS));
    assertNull(props2.get(COLOR_SCHEME));
    assertEquals(props1.get(AUTO_RANGE), props2.get(AUTO_RANGE));
    assertEquals(props1.get(GLOBAL_RANGE), props2.get(GLOBAL_RANGE));
    assertEquals(props1.get(RANGE), props2.get(RANGE));
    assertEquals(props1.get(COLORS), props2.get(COLORS));
    assertEquals(props1.get(ORIENTATION), props2.get(ORIENTATION));
    assertEquals(props1.get(BORDER_COLOR), props2.get(BORDER_COLOR));
    assertEquals(props1.get(BORDER_WIDTH), props2.get(BORDER_WIDTH));
    assertEquals(ITEM_LABELS_NAME, ((CyColumnIdentifier) props2.get(ITEM_LABELS_COLUMN)).getColumnName());
    assertEquals("labels-2", ((CyColumnIdentifier) props2.get(DOMAIN_LABELS_COLUMN)).getColumnName());
    assertEquals("labels.3", ((CyColumnIdentifier) props2.get(RANGE_LABELS_COLUMN)).getColumnName());
    assertEquals(props1.get(DOMAIN_LABEL_POSITION), props2.get(DOMAIN_LABEL_POSITION));
    assertEquals(props1.get(ITEM_LABELS), props2.get(ITEM_LABELS));
    assertEquals(props1.get(SHOW_ITEM_LABELS), props2.get(SHOW_ITEM_LABELS));
    assertEquals(props1.get(SHOW_DOMAIN_AXIS), props2.get(SHOW_DOMAIN_AXIS));
    assertEquals(props1.get(SHOW_RANGE_AXIS), props2.get(SHOW_RANGE_AXIS));
    assertEquals(props1.get(AXIS_WIDTH), props2.get(AXIS_WIDTH));
    assertEquals(props1.get(AXIS_COLOR), props2.get(AXIS_COLOR));
    assertEquals(props1.get(LINE_WIDTH), props2.get(LINE_WIDTH));
    assertNull(props2.get(VALUES));
    // When calling the internal get methods, some property values are converted to internal types,
    // which are not exposed to the API client code
    assertEquals(props2.get(DATA_COLUMNS), chart.getList(DATA_COLUMNS, CyColumnIdentifier.class));
    // Test default!
    assertEquals(ColorScheme.CONTRASTING, chart.get(COLOR_SCHEME, ColorScheme.class, ColorScheme.CONTRASTING));
    assertEquals(Boolean.TRUE, chart.get(AUTO_RANGE, Boolean.class));
    assertEquals(Boolean.FALSE, chart.get(GLOBAL_RANGE, Boolean.class));
    assertEquals(props1.get(RANGE), chart.getList(RANGE, Double.class));
    assertEquals(props1.get(COLORS), chart.getList(COLORS, Color.class));
    assertEquals(Orientation.VERTICAL, chart.get(ORIENTATION, Orientation.class));
    assertEquals(Color.WHITE, chart.get(BORDER_COLOR, Color.class));
    assertEquals(new Float(2.5f), chart.get(BORDER_WIDTH, Float.class));
    assertEquals(ITEM_LABELS_NAME, chart.get(ITEM_LABELS_COLUMN, CyColumnIdentifier.class).getColumnName());
    assertEquals("labels-2", chart.get(DOMAIN_LABELS_COLUMN, CyColumnIdentifier.class).getColumnName());
    assertEquals("labels.3", chart.get(RANGE_LABELS_COLUMN, CyColumnIdentifier.class).getColumnName());
    assertEquals(LabelPosition.UP_45, chart.get(DOMAIN_LABEL_POSITION, LabelPosition.class));
    assertEquals(props1.get(ITEM_LABELS), chart.getList(ITEM_LABELS, String.class));
    assertEquals(Boolean.TRUE, chart.get(SHOW_ITEM_LABELS, Boolean.class));
    assertEquals(Boolean.TRUE, chart.get(SHOW_DOMAIN_AXIS, Boolean.class));
    assertEquals(Boolean.FALSE, chart.get(SHOW_RANGE_AXIS, Boolean.class));
    assertEquals(new Float(1.5f), chart.get(AXIS_WIDTH, Float.class));
    assertEquals(Color.YELLOW, chart.get(AXIS_COLOR, Color.class));
    assertEquals(new Float(4.2f), chart.get(LINE_WIDTH, Float.class));
    // Lists must never be null!
    assertTrue(chart.getList(VALUES, Double.class).isEmpty());
}
Also used : Color(java.awt.Color) ColorScheme(org.cytoscape.ding.customgraphics.ColorScheme) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) Orientation(org.cytoscape.ding.customgraphics.Orientation) LineChart(org.cytoscape.ding.internal.charts.line.LineChart) AbstractCustomGraphics2Test(org.cytoscape.ding.customgraphics.AbstractCustomGraphics2Test) Test(org.junit.Test)

Example 20 with CyColumnIdentifier

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

the class RingChartTest method testChartProperties.

@Test
public void testChartProperties() {
    final RingChart chart = new RingChart(props1, serviceRegistrar);
    // The chart properties has to return exactly the same values,
    // except column names, which are converted to CyColumIdentifier when set as String
    Map<String, Object> props2 = chart.getProperties();
    assertEquals(props1.get(DATA_COLUMNS), props2.get(DATA_COLUMNS));
    assertEquals(props1.get(COLOR_SCHEME), props2.get(COLOR_SCHEME));
    assertEquals(props1.get(COLORS), props2.get(COLORS));
    assertEquals(props1.get(BORDER_COLOR), props2.get(BORDER_COLOR));
    assertEquals(props1.get(BORDER_WIDTH), props2.get(BORDER_WIDTH));
    assertEquals("labels1", ((CyColumnIdentifier) props2.get(ITEM_LABELS_COLUMN)).getColumnName());
    assertEquals(props1.get(ITEM_LABELS), props2.get(ITEM_LABELS));
    assertEquals(props1.get(SHOW_ITEM_LABELS), props2.get(SHOW_ITEM_LABELS));
    assertEquals(props1.get(START_ANGLE), props2.get(START_ANGLE));
    assertEquals(props1.get(HOLE_SIZE), props2.get(HOLE_SIZE));
    assertNull(props2.get(VALUES));
    // When calling the internal get methods, some property values are converted to internal types,
    // which are not exposed to the API client code
    assertEquals(props2.get(DATA_COLUMNS), chart.getList(DATA_COLUMNS, CyColumnIdentifier.class));
    assertEquals(ColorScheme.CUSTOM, chart.get(COLOR_SCHEME, ColorScheme.class));
    assertEquals(props1.get(COLORS), chart.getList(COLORS, Color.class));
    assertEquals(Color.WHITE, chart.get(BORDER_COLOR, Color.class));
    assertEquals(new Float(2.5f), chart.get(BORDER_WIDTH, Float.class));
    assertEquals("labels1", chart.get(ITEM_LABELS_COLUMN, CyColumnIdentifier.class).getColumnName());
    assertEquals(props1.get(ITEM_LABELS), chart.getList(ITEM_LABELS, String.class));
    assertEquals(Boolean.TRUE, chart.get(SHOW_ITEM_LABELS, Boolean.class));
    assertEquals(new Double(-45), chart.get(START_ANGLE, Double.class));
    assertEquals(new Double(-2.5), chart.get(HOLE_SIZE, Double.class));
    // Must never be null!
    assertTrue(chart.getList(VALUES, Double.class).isEmpty());
}
Also used : RingChart(org.cytoscape.ding.internal.charts.ring.RingChart) Color(java.awt.Color) ColorScheme(org.cytoscape.ding.customgraphics.ColorScheme) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) AbstractCustomGraphics2Test(org.cytoscape.ding.customgraphics.AbstractCustomGraphics2Test) Test(org.junit.Test)

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