use of com.google.refine.browsing.facets.ScatterplotFacet in project OpenRefine by OpenRefine.
the class Engine method initializeFromJSON.
public void initializeFromJSON(JSONObject o) throws JSONException {
if (o == null) {
return;
}
if (o.has("facets") && !o.isNull("facets")) {
JSONArray a = o.getJSONArray("facets");
int length = a.length();
for (int i = 0; i < length; i++) {
JSONObject fo = a.getJSONObject(i);
String type = fo.has("type") ? fo.getString("type") : "list";
Facet facet = null;
if ("list".equals(type)) {
facet = new ListFacet();
} else if ("range".equals(type)) {
facet = new RangeFacet();
} else if ("timerange".equals(type)) {
facet = new TimeRangeFacet();
} else if ("scatterplot".equals(type)) {
facet = new ScatterplotFacet();
} else if ("text".equals(type)) {
facet = new TextSearchFacet();
}
if (facet != null) {
facet.initializeFromJSON(_project, fo);
_facets.add(facet);
}
}
}
// for backward compatibility
if (o.has(INCLUDE_DEPENDENT) && !o.isNull(INCLUDE_DEPENDENT)) {
_mode = o.getBoolean(INCLUDE_DEPENDENT) ? Mode.RecordBased : Mode.RowBased;
}
if (o.has(MODE) && !o.isNull(MODE)) {
_mode = MODE_ROW_BASED.equals(o.getString(MODE)) ? Mode.RowBased : Mode.RecordBased;
}
}
use of com.google.refine.browsing.facets.ScatterplotFacet in project OpenRefine by OpenRefine.
the class ScatterplotFacetTests method serializeScatterplotFacet.
@Test
public void serializeScatterplotFacet() throws JsonParseException, JsonMappingException, IOException {
Project project = createCSVProject("my column,e\n" + "89.2,89.2\n" + "-45.9,-45.9\n" + "blah,blah\n" + "0.4,0.4\n");
Engine engine = new Engine(project);
project.rows.get(0).cells.set(0, new Cell(89.2, null));
project.rows.get(0).cells.set(1, new Cell(89.2, null));
project.rows.get(1).cells.set(0, new Cell(-45.9, null));
project.rows.get(1).cells.set(1, new Cell(-45.9, null));
project.rows.get(3).cells.set(0, new Cell(0.4, null));
project.rows.get(3).cells.set(1, new Cell(0.4, null));
ScatterplotFacetConfig config = ParsingUtilities.mapper.readValue(configJson, ScatterplotFacetConfig.class);
ScatterplotFacet facet = config.apply(project);
facet.computeChoices(project, engine.getAllFilteredRows());
TestUtils.isSerializedTo(facet, facetJson);
RowFilter filter = facet.getRowFilter(project);
assertTrue(filter.filterRow(project, 0, project.rows.get(0)));
assertFalse(filter.filterRow(project, 1, project.rows.get(1)));
assertTrue(filter.filterRow(project, 3, project.rows.get(3)));
}
Aggregations