fixe rotation parsing in scatterplot facet (#3926)

* fixes #3344

* Remove try/catch block no longer useful
This commit is contained in:
Warpeas 2021-05-26 20:08:42 +08:00 committed by GitHub
parent dd4eb781e1
commit 3adc03c0db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 112 additions and 68 deletions

View File

@ -76,8 +76,8 @@ public class GetScatterplotCommand extends Command {
Project project = getProject(request);
Engine engine = getEngine(request, project);
PlotterConfig conf = ParsingUtilities.mapper.readValue(
request.getParameter("plotter"),
PlotterConfig.class);
request.getParameter("plotter"),
PlotterConfig.class);
response.setHeader("Content-Type", "image/png");
@ -98,28 +98,28 @@ public class GetScatterplotCommand extends Command {
}
protected static class PlotterConfig {
@JsonProperty(ScatterplotFacet.SIZE)
public int size = 100;
@JsonProperty(ScatterplotFacet.DOT)
double dot = 100;
@JsonIgnore
public int dim_x = ScatterplotFacet.LIN;
@JsonIgnore
public int dim_y = ScatterplotFacet.LIN;
@JsonProperty(ScatterplotFacet.ROTATION)
public int rotation = ScatterplotFacet.NO_ROTATION;
@JsonProperty(ScatterplotFacet.COLOR)
public String color_str = "000000";
@JsonProperty(ScatterplotFacet.BASE_COLOR)
public String base_color_str = null;
@JsonProperty(ScatterplotFacet.X_COLUMN_NAME)
public String columnName_x = "";
@JsonProperty(ScatterplotFacet.X_EXPRESSION)
public String expression_x = "value";
@JsonProperty(ScatterplotFacet.Y_COLUMN_NAME)
public String columnName_y = "";
@JsonProperty(ScatterplotFacet.Y_EXPRESSION)
public String expression_y = "value";
@JsonProperty(ScatterplotFacet.SIZE)
public int size = 100;
@JsonProperty(ScatterplotFacet.DOT)
double dot = 100;
@JsonIgnore
public int dim_x = ScatterplotFacet.LIN;
@JsonIgnore
public int dim_y = ScatterplotFacet.LIN;
@JsonProperty(ScatterplotFacet.ROTATION)
public int rotation = ScatterplotFacet.NO_ROTATION;
@JsonProperty(ScatterplotFacet.COLOR)
public String color_str = "000000";
@JsonProperty(ScatterplotFacet.BASE_COLOR)
public String base_color_str = null;
@JsonProperty(ScatterplotFacet.X_COLUMN_NAME)
public String columnName_x = "";
@JsonProperty(ScatterplotFacet.X_EXPRESSION)
public String expression_x = "value";
@JsonProperty(ScatterplotFacet.Y_COLUMN_NAME)
public String columnName_y = "";
@JsonProperty(ScatterplotFacet.Y_EXPRESSION)
public String expression_y = "value";
@JsonProperty(ScatterplotFacet.DIM_X)
public String getDimX() {
@ -133,22 +133,18 @@ public class GetScatterplotCommand extends Command {
@JsonProperty(ScatterplotFacet.DIM_X)
public void setDimX(String dim) {
dim_x = dim.equals("lin") ? ScatterplotFacet.LIN : ScatterplotFacet.LOG;
dim_x = dim.equals("lin") ? ScatterplotFacet.LIN : ScatterplotFacet.LOG;
}
@JsonProperty(ScatterplotFacet.DIM_Y)
public void setDimY(String dim) {
dim_y = dim.equals("lin") ? ScatterplotFacet.LIN : ScatterplotFacet.LOG;
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) {
;
}
this.rotation = ScatterplotFacet.ScatterplotFacetConfig.getRotation(rotation.toString());
}
}
@ -165,9 +161,9 @@ public class GetScatterplotCommand extends Command {
Evaluable eval_x = null;
Evaluable eval_y = null;
Color color = new Color(Integer.parseInt(o.color_str,16));
Color color = new Color(Integer.parseInt(o.color_str, 16));
Color base_color = o.base_color_str != null ? new Color(Integer.parseInt(o.base_color_str,16)) : null;
Color base_color = o.base_color_str != null ? new Color(Integer.parseInt(o.base_color_str, 16)) : null;
if (o.columnName_x.length() > 0) {
Column x_column = project.columnModel.getColumnByName(o.columnName_x);
@ -220,8 +216,8 @@ public class GetScatterplotCommand extends Command {
if (index_x != null && index_y != null && index_x.isNumeric() && index_y.isNumeric()) {
ScatterplotDrawingRowVisitor drawer = new ScatterplotDrawingRowVisitor(
columnIndex_x, columnIndex_y, min_x, max_x, min_y, max_y,
o.size, o.dim_x, o.dim_y, o.rotation, o.dot, color
columnIndex_x, columnIndex_y, min_x, max_x, min_y, max_y,
o.size, o.dim_x, o.dim_y, o.rotation, o.dot, color
);
if (base_color != null) {

View File

@ -76,6 +76,42 @@ public class ScatterplotDrawCommandTests {
+ "\"to_y\":0,"
+ "\"color\":\"ff6a00\"}";
public static String configJsonWithCW = "{"
+ "\"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\":\"cw\","
+ "\"type\":\"scatterplot\","
+ "\"from_x\":0,"
+ "\"to_x\":0,"
+ "\"from_y\":0,"
+ "\"to_y\":0,"
+ "\"color\":\"ff6a00\"}";
public static String configJsonWithCCW = "{"
+ "\"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\":\"ccw\","
+ "\"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);
@ -88,7 +124,19 @@ public class ScatterplotDrawCommandTests {
@Test
public void testParseConfigWithNone() throws JsonParseException, JsonMappingException, IOException {
GetScatterplotCommand.PlotterConfig config = ParsingUtilities.mapper.readValue(configJsonWithNone, GetScatterplotCommand.PlotterConfig.class);
Assert.assertEquals(0, config.rotation);
Assert.assertEquals(ScatterplotFacet.NO_ROTATION, config.rotation);
}
@Test
public void testParseConfigWithCW() throws JsonParseException, JsonMappingException, IOException {
GetScatterplotCommand.PlotterConfig config = ParsingUtilities.mapper.readValue(configJsonWithCW, GetScatterplotCommand.PlotterConfig.class);
Assert.assertEquals(ScatterplotFacet.ROTATE_CW, config.rotation);
}
@Test
public void testParseConfigWithCCW() throws JsonParseException, JsonMappingException, IOException {
GetScatterplotCommand.PlotterConfig config = ParsingUtilities.mapper.readValue(configJsonWithCCW, GetScatterplotCommand.PlotterConfig.class);
Assert.assertEquals(ScatterplotFacet.ROTATE_CCW, config.rotation);
}
}