Skip to content

Commit

Permalink
histogram-click-based filtering now implemented; histogram sort corre…
Browse files Browse the repository at this point in the history
…cted; library directory pointers in nbproject now corrected
  • Loading branch information
omgpotatoes committed Mar 7, 2013
1 parent 1a7ea6e commit 285620e
Show file tree
Hide file tree
Showing 11 changed files with 392 additions and 129 deletions.
21 changes: 21 additions & 0 deletions nbproject/private/private.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1">
<file>
<url>src/emr_vis_nlp/view/doc_grid/DocumentGrid.java</url>
<line>245</line>
</file>
<file>
<url>src/emr_vis_nlp/view/doc_grid/DocumentGridTable.java</url>
<line>73</line>
</file>
<file>
<url>src/emr_vis_nlp/model/DocDetailsTableModel.java</url>
<line>26</line>
</file>
<file>
<url>src/emr_vis_nlp/ml/MLPredictor.java</url>
<line>19</line>
</file>
</editor-bookmarks>
</project-private>
2 changes: 1 addition & 1 deletion resources/backend/temp.arff

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions src/emr_vis_nlp/controller/AttrValPredicate.java
@@ -0,0 +1,75 @@

package emr_vis_nlp.controller;

import java.util.Objects;

/**
* Tuple class for storing an attribute name and a target value.
*
* @author alexander.p.conrad
*/
public class AttrValPredicate {

private String attrName;
private String attrVal;

public AttrValPredicate(String attrName, String attrVal) {
this.attrName = attrName;
this.attrVal = attrVal;
}

public String getAttrName() {
return attrName;
}

public void setAttrName(String attrName) {
this.attrName = attrName;
}

public String getAttrVal() {
return attrVal;
}

public void setAttrVal(String attrVal) {
this.attrVal = attrVal;
}

public String getTrueStrPred() {
return attrName+" == '"+attrVal+"'";
}

public String getFalseStrPred() {
return "["+attrName+"] != '"+attrVal+"'";
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final AttrValPredicate other = (AttrValPredicate) obj;
if (!Objects.equals(this.attrName, other.attrName)) {
return false;
}
if (!Objects.equals(this.attrVal, other.attrVal)) {
return false;
}
return true;
}

@Override
public int hashCode() {
int hash = 7;
hash = 41 * hash + Objects.hashCode(this.attrName);
hash = 41 * hash + Objects.hashCode(this.attrVal);
return hash;
}





}
48 changes: 40 additions & 8 deletions src/emr_vis_nlp/controller/MainController.java
Expand Up @@ -11,12 +11,9 @@
import emr_vis_nlp.view.doc_grid.DocumentGridTable;
import emr_vis_nlp.view.doc_map.DocumentTreeMapView;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.table.TableModel;
import javax.swing.text.AbstractDocument;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
Expand Down Expand Up @@ -75,7 +72,11 @@ public class MainController {
* backing table for current document grid (if any)
*/
DocumentGridTable documentGridTable = null;

/*
* list of predicates for document disabling
*/
private Map<AttrValPredicate, Boolean> disabledAttrValsMap;

/**
* Factory method for generating a singleton MainController.
*
Expand All @@ -94,6 +95,7 @@ public static MainController getMainController() {
private MainController() {
activePopups = new ArrayList<>();
activePopupIDs = new ArrayList<>();
disabledAttrValsMap = new HashMap<>();
}

/**
Expand Down Expand Up @@ -592,15 +594,45 @@ public void unhighlightAllDocs() {
}

public void disableDocsWithAttrVal(String attrName, String attrValue) {
//TODO
AttrValPredicate pred = new AttrValPredicate(attrName, attrValue);
disabledAttrValsMap.put(pred, true);
attrValPairsUpdated();
}

public void enableDocsWithAttrVal(String attrName, String attrValue) {
//TODO
AttrValPredicate pred = new AttrValPredicate(attrName, attrValue);
if (disabledAttrValsMap.containsKey(pred)) {
disabledAttrValsMap.remove(pred);
}
attrValPairsUpdated();
}

public void enableAllDocs() {
//TODO
disabledAttrValsMap.clear();
attrValPairsUpdated();
}

private void attrValPairsUpdated() {
// update appropriate components
// build predicate string for Prefuse components
StringBuilder predDisabledAttrValsBuilder = new StringBuilder();
Set<AttrValPredicate> keySet = disabledAttrValsMap.keySet();
Iterator<AttrValPredicate> keySetIterator = keySet.iterator();
while (keySetIterator.hasNext()) {
AttrValPredicate pred = keySetIterator.next();
// predDisabledAttrValsBuilder.append(pred.getTrueStrPred());
predDisabledAttrValsBuilder.append(pred.getFalseStrPred());
if (keySetIterator.hasNext()) {
// predDisabledAttrValsBuilder.append(" OR ");
predDisabledAttrValsBuilder.append(" AND ");
}
}
// push string to appropriate Prefuse components
String predDisabledAttrVals = predDisabledAttrValsBuilder.toString();
if (documentGrid != null) {
documentGrid.resetDocsVisiblePredicate(predDisabledAttrVals);
}

}

/**
Expand Down
1 change: 1 addition & 0 deletions src/emr_vis_nlp/main/MainTabbedView.java
Expand Up @@ -889,6 +889,7 @@ public void run() {
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButtonReset;
private javax.swing.JButton jButtonSelectAllDocGrid;
Expand Down
24 changes: 14 additions & 10 deletions src/emr_vis_nlp/view/JTableCombos.java
Expand Up @@ -28,9 +28,11 @@ public void mouseClicked(MouseEvent e) {
int column = target.getSelectedColumn();
if (column == 2) {
// in histogram column
Rectangle cellRect = target.getCellRect(row, column, false);
// translate properly from table to model!
int modelRow = convertRowIndexToModel(row);
Rectangle cellRect = target.getCellRect(modelRow, column, false);
// Rectangle cellRect = target.getCellRect(row, column, true);
VarBarChartForCell chart = (VarBarChartForCell)(getModel().getValueAt(row, column));
VarBarChartForCell chart = (VarBarChartForCell)(getModel().getValueAt(modelRow, column));
// figure out which of the cols was clicked
// int xPointer = e.getXOnScreen();
// int yPointer = e.getYOnScreen();
Expand All @@ -56,7 +58,7 @@ public void mouseClicked(MouseEvent e) {
// TODO generalize this code to multiple regions!
double regionBound1 = xChart + widthChart * 1.0/3.0;
double regionBound2 = xChart + widthChart * 2.0/3.0;
chart.unhighlightCells();
// chart.unhighlightCells();
if (xPointer > xChart && xPointer < regionBound1) {
chart.clickOnCell(0);
} else if (xPointer < regionBound2) {
Expand All @@ -68,13 +70,15 @@ public void mouseClicked(MouseEvent e) {
System.err.println("JTableCombos: unexpected mouse click event: "+e.toString());
}
// clear all other boxes
int numRows = getModel().getRowCount();
for (int r=0; r<numRows; r++) {
if (r != row) {
VarBarChartForCell otherChart = (VarBarChartForCell)(getModel().getValueAt(r, column));
otherChart.unhighlightCells();
}
}
// click now applies to filtering rather than highlighting
// int numRows = getModel().getRowCount();
// //for (int r=0; r<rows; r++) {
// for (int r=0; r<numRows; r++) {
// if (r != row) {
// VarBarChartForCell otherChart = (VarBarChartForCell)(getModel().getValueAt(r, column));
// otherChart.unhighlightCells();
// }
// }

((AbstractTableModel)target.getModel()).fireTableDataChanged();
}
Expand Down
34 changes: 21 additions & 13 deletions src/emr_vis_nlp/view/VarBarChartForCell.java
Expand Up @@ -35,6 +35,8 @@ public class VarBarChartForCell extends JPanel {
private List<Document> allDocs;
// list of all cols for cell
private List<VarBarChartColumn> allCols;
// current tooltiptext
private String toolTipText = "";

public VarBarChartForCell(MainController controller, String attrName, List<Document> allDocs) {
super();
Expand Down Expand Up @@ -191,7 +193,8 @@ public void rebuildComponents() {
// // old alpha code for incorporating cluster selection no longer needed; see previous version's code if needed

// update tooltip text
setToolTipText(attrName+": "+((int)(100*valPercs[0]))+"% N/A, "+((int)(100*valPercs[1]))+"% Fail, "+((int)(100*valPercs[2]))+"% Pass (click to select)");
toolTipText = attrName+": "+((int)(100*valPercs[0]))+"% N/A, "+((int)(100*valPercs[1]))+"% Fail, "+((int)(100*valPercs[2]))+"% Pass (click to select)";
setToolTipText(toolTipText);

}

Expand Down Expand Up @@ -328,6 +331,11 @@ public void unhighlightCells() {
}
}

@Override
public String toString() {
return toolTipText;
}

// warning! mouse events are being intercepted by the JTable in which this VarBarChart is embedded!
class VarBarChartColumn extends JPanel implements MouseListener {

Expand Down Expand Up @@ -473,22 +481,22 @@ public void mouseClicked(MouseEvent e) {
// debug
System.out.println("debug: varBarChartColumn: mouseClicked for attrName = "+attrName+", attrVal = "+attrVal);
if (isEnabled) {
// // for testing, just highlight
// if (isHighlighted) {
// controller.unhighlightAllDocs();
// isHighlighted = false;
// } else {
// controller.highlightDocsWithAttrVal(attrName, attrVal);
// isHighlighted = true;
// }
// disable designated docs
// TODO
// isEnabled = false;
isEnabled = false;
controller.disableDocsWithAttrVal(attrName, attrVal);

// for testing, just highlight
if (isHighlighted) {
controller.unhighlightAllDocs();
isHighlighted = false;
} else {
controller.highlightDocsWithAttrVal(attrName, attrVal);
isHighlighted = true;
}
} else {
// enable designated docs
// TODO
// isEnabled = true;
isEnabled = true;
controller.enableDocsWithAttrVal(attrName, attrVal);
}

repaint();
Expand Down
15 changes: 13 additions & 2 deletions src/emr_vis_nlp/view/doc_grid/DocGridTableSelectorModel.java
Expand Up @@ -74,7 +74,7 @@ public DocGridTableSelectorModel(List<String> _allAttributes) {
for (int a = 0; a < _allAttributes.size(); a++) {
String attributeName = _allAttributes.get(a);
allAttributes.add(attributeName);
JComboBox attributeSelectorBox = new JComboBox(optionList);
JComboBox attributeSelectorBox = new JComboBoxSortable(optionList);
allAttributesSelectorBoxes.add(attributeSelectorBox);
if (a < numOptions) {
attributeSelectorBox.setSelectedIndex(a);
Expand Down Expand Up @@ -340,6 +340,17 @@ public void resetVarBarCharts() {
// }
}


public class JComboBoxSortable extends JComboBox {

public JComboBoxSortable(String[] vals) {
super(vals);
}

@Override
public String toString() {
return getSelectedItem().toString();
}

}

}

0 comments on commit 285620e

Please sign in to comment.