Added length function and support for creating custom numeric (range slider) facets.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@48 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-02-05 19:43:43 +00:00
parent 16dda46a61
commit 3e30ab2a33
4 changed files with 88 additions and 31 deletions

View File

@ -29,6 +29,7 @@ public class RangeFacet implements Facet {
protected double _from;
protected double _to;
protected boolean _selected;
public RangeFacet() {
}
@ -79,36 +80,49 @@ public class RangeFacet implements Facet {
_mode = o.getString("mode");
if ("min".equals(_mode)) {
_from = o.getDouble("from");
if (o.has("from")) {
_from = o.getDouble("from");
_selected = true;
}
} else if ("max".equals(_mode)) {
_to = o.getDouble("to");
if (o.has("to")) {
_to = o.getDouble("to");
_selected = true;
}
} else {
_from = o.getDouble("from");
_to = o.getDouble("to");
if (o.has("from") && o.has("to")) {
_from = o.getDouble("from");
_to = o.getDouble("to");
_selected = true;
}
}
}
@Override
public RowFilter getRowFilter() {
if ("min".equals(_mode)) {
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
protected boolean checkValue(double d) {
return d >= _from;
if (_selected) {
if ("min".equals(_mode)) {
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
protected boolean checkValue(double d) {
return d >= _from;
};
};
};
} else if ("max".equals(_mode)) {
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
protected boolean checkValue(double d) {
return d <= _to;
} else if ("max".equals(_mode)) {
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
protected boolean checkValue(double d) {
return d <= _to;
};
};
};
} else {
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
protected boolean checkValue(double d) {
return d >= _from && d <= _to;
};
};
}
} else {
return new ExpressionNumberComparisonRowFilter(_eval, _cellIndex) {
protected boolean checkValue(double d) {
return d >= _from && d <= _to;
};
};
}
return null;
}
}
@Override
@ -127,6 +141,14 @@ public class RangeFacet implements Facet {
_step = index.getStep();
_baseBins = index.getBins();
if (_selected) {
_from = Math.max(_from, _min);
_to = Math.min(_to, _max);
} else {
_from = _min;
_to = _max;
}
ExpressionNumericRowBinner binner =
new ExpressionNumericRowBinner(_eval, _cellIndex, index);

View File

@ -17,6 +17,7 @@ import com.metaweb.gridworks.expr.functions.IsBlank;
import com.metaweb.gridworks.expr.functions.IsNotBlank;
import com.metaweb.gridworks.expr.functions.IsNotNull;
import com.metaweb.gridworks.expr.functions.IsNull;
import com.metaweb.gridworks.expr.functions.Length;
import com.metaweb.gridworks.expr.functions.Not;
import com.metaweb.gridworks.expr.functions.Or;
import com.metaweb.gridworks.expr.functions.Replace;
@ -44,6 +45,7 @@ public class Parser {
functionTable.put("substring", new Slice());
functionTable.put("replace", new Replace());
functionTable.put("split", new Split());
functionTable.put("length", new Length());
functionTable.put("and", new And());
functionTable.put("or", new Or());

View File

@ -0,0 +1,27 @@
package com.metaweb.gridworks.expr.functions;
import java.util.Properties;
import com.metaweb.gridworks.expr.Function;
public class Length implements Function {
@Override
public Object call(Properties bindings, Object[] args) {
if (args.length == 1) {
Object v = args[0];
if (v != null) {
if (v.getClass().isArray()) {
Object[] a = (Object[]) v;
return a.length;
} else {
String s = (v instanceof String ? (String) v : v.toString());
return s.length();
}
}
}
return null;
}
}

View File

@ -370,7 +370,11 @@ DataTableView.prototype._createMenuForColumnHeader = function(column, index, elm
},
{
label: "Custom Text Facet ...",
click: function() { self._doFilterByExpressionPrompt(column); }
click: function() { self._doFilterByExpressionPrompt(column, "value", "list"); }
},
{
label: "Custom Numeric Facet ...",
click: function() { self._doFilterByExpressionPrompt(column, "value", "range"); }
},
{},
{
@ -637,21 +641,23 @@ DataTableView.prototype._createMenuForColumnHeader = function(column, index, elm
], elmt, { width: "120px", horizontal: false });
};
DataTableView.prototype._doFilterByExpressionPrompt = function(column, expression) {
DataTableView.prototype._doFilterByExpressionPrompt = function(column, expression, type) {
var self = this;
DataTableView.promptExpressionOnVisibleRows(
column,
"Custom Filter on " + column.headerLabel,
"value",
expression,
function(expression) {
ui.browsingEngine.addFacet(
"list",
{
"name" : column.headerLabel + ": " + expression,
"cellIndex" : column.cellIndex,
"expression" : expression
}
);
var config = {
"name" : column.headerLabel + ": " + expression,
"cellIndex" : column.cellIndex,
"expression" : expression
};
if (type == "range") {
config.mode = "range";
}
ui.browsingEngine.addFacet(type, config);
}
);
};