Fix scatterplot facet filtering

This commit is contained in:
Antonin Delpeuch 2019-09-12 11:52:28 +01:00
parent 573ba18e6d
commit 36150a874d
4 changed files with 45 additions and 2 deletions

View File

@ -104,7 +104,7 @@ public class ScatterplotFacet implements Facet {
protected int rotation;
@JsonIgnore
protected double l;
protected double l = 1.;
@JsonProperty(DOT)
protected double dot;

View File

@ -140,6 +140,16 @@ public class GetScatterplotCommand extends Command {
public void setDimY(String dim) {
dim_y = dim.equals("lin") ? ScatterplotFacet.LIN : ScatterplotFacet.LOG;
}
// rotation can be set to "none" (a JSON string) in which case it should be ignored
@JsonProperty(ScatterplotFacet.ROTATION)
public void setRotation(Object rotation) {
try {
this.rotation = Integer.parseInt(rotation.toString());
} catch(NumberFormatException e) {
;
}
}
}
public void draw(OutputStream output, Project project, Engine engine, PlotterConfig o) throws IOException {

View File

@ -26,6 +26,9 @@
******************************************************************************/
package com.google.refine.browsing.facets;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.io.IOException;
import org.testng.annotations.Test;
@ -34,6 +37,7 @@ import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.google.refine.RefineTest;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.RowFilter;
import com.google.refine.browsing.facets.ScatterplotFacet;
import com.google.refine.browsing.facets.ScatterplotFacet.ScatterplotFacetConfig;
import com.google.refine.model.Cell;
@ -102,7 +106,11 @@ public class ScatterplotFacetTests extends RefineTest {
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)));
}
}

View File

@ -58,6 +58,25 @@ public class ScatterplotDrawCommandTests {
+ "\"color\":\"ff6a00\""
+ "}";
public static String configJsonWithNone = "{"
+ "\"name\":\"b (x) vs. y (y)\","
+ "\"cx\":\"b\","
+ "\"cy\":\"y\","
+ "\"l\":150,"
+ "\"ex\":\"value\","
+ "\"ey\":\"value\","
+ "\"dot\":1.4,"
+ "\"dim_x\":\"lin\","
+ "\"dim_y\":\"lin\","
+ "\"r\":\"none\","
+ "\"type\":\"scatterplot\","
+ "\"from_x\":0,"
+ "\"to_x\":0,"
+ "\"from_y\":0,"
+ "\"to_y\":0,"
+ "\"color\":\"ff6a00\"}";
@Test
public void testParseConfig() throws JsonParseException, JsonMappingException, IOException {
GetScatterplotCommand.PlotterConfig config = ParsingUtilities.mapper.readValue(configJson, GetScatterplotCommand.PlotterConfig.class);
@ -67,4 +86,10 @@ public class ScatterplotDrawCommandTests {
Assert.assertEquals(ScatterplotFacet.LIN, config.dim_y);
}
@Test
public void testParseConfigWithNone() throws JsonParseException, JsonMappingException, IOException {
GetScatterplotCommand.PlotterConfig config = ParsingUtilities.mapper.readValue(configJsonWithNone, GetScatterplotCommand.PlotterConfig.class);
Assert.assertEquals(0, config.rotation);
}
}