Changeset 343


Ignore:
Timestamp:
Apr 5, 2012, 2:38:06 PM (5 years ago)
Author:
tim.te.beek@…
Message:

Update the plot title to the common prefix of selected attributes

Location:
trunk/expression-data-viewer/src/main/java/nl/nbic/brs/expview
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/expression-data-viewer/src/main/java/nl/nbic/brs/expview/model/AttributesModel.java

    r340 r343  
    2929         * @return array with the names of selected attributes
    3030         */
    31         protected String[] getSelectedAttributes() {
     31        public String[] getSelectedAttributes() {
    3232                int[] selectedAttributeIndices = selectedAttributesModel.getSelectedAttributeIndices();
    3333                String[] selectedAttributes = new String[selectedAttributeIndices.length];
  • trunk/expression-data-viewer/src/main/java/nl/nbic/brs/expview/view/PlotDialog.java

    r342 r343  
    1717import javax.swing.JScrollPane;
    1818import javax.swing.LayoutStyle.ComponentPlacement;
     19import javax.swing.event.ListSelectionEvent;
     20import javax.swing.event.ListSelectionListener;
    1921
    2022import lombok.Getter;
    2123
     24import org.apache.commons.lang.StringUtils;
    2225import org.jfree.chart.ChartFactory;
    2326import org.jfree.chart.ChartPanel;
     
    3134public class PlotDialog extends JDialog {
    3235        @Getter
    33         private PlottingParams  plottingParams  = new PlottingParams();
     36        PlottingParams                  plottingParams  = new PlottingParams();
    3437
    3538        private JComboBox               networkCombobox;
     
    4346        private JScrollPane             attributesListPane;
    4447
     48        JFreeChart                              lineChart;
    4549        private ChartPanel              chartPanel;
    4650
    4751        public PlotDialog(final Frame owner) {
    4852                super(owner);
     53
     54                // Update chart properties when we can
     55                ChartUpdater chartUpdater = new ChartUpdater();
     56                plottingParams.getAttributesModel().addListSelectionListener(chartUpdater);
    4957
    5058                initComponents();
     
    5361
    5462        private void initComponents() {
    55                 // TODO Add better guesses for these labels
    5663                // TODO Improve the plot graphics, subtitle, hide advertisement, etc
    5764                // TODO Make the plot itself interactive to for instance toggle specific plot lines by clicking on them
     
    5966                String categoryAxisLabel = "attributes";
    6067                String valueAxisLabel = "values";
    61                 JFreeChart lineChart = ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel, plottingParams.getDataset(), PlotOrientation.VERTICAL, true, true, true);
     68                lineChart = ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel, plottingParams.getDataset(), PlotOrientation.VERTICAL, true, true, true);
    6269                chartPanel = new ChartPanel(lineChart);
    6370
     
    140147                setMinimumSize(getSize());
    141148        }
     149
     150        class ChartUpdater implements ListSelectionListener {
     151                @Override
     152                public void valueChanged(final ListSelectionEvent e) {
     153                        if (e.getValueIsAdjusting())
     154                                return;
     155
     156                        // Update category axis label to the common prefix of the selected attributes, if there is any
     157                        String[] selectedAttributes = plottingParams.getAttributesModel().getSelectedAttributes();
     158                        String commonPrefix = StringUtils.getCommonPrefix(selectedAttributes);
     159                        // But only if the common prefix is not too short (arbitrary)
     160                        if (3 < commonPrefix.length())
     161                                lineChart.setTitle(commonPrefix);
     162                }
     163        }
    142164}
Note: See TracChangeset for help on using the changeset viewer.