Fix scatterplot drawing command, closes #2117
This commit is contained in:
parent
c35b2e154f
commit
573ba18e6d
@ -47,6 +47,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.refine.browsing.Engine;
|
||||
import com.google.refine.browsing.FilteredRows;
|
||||
@ -101,9 +102,9 @@ public class GetScatterplotCommand extends Command {
|
||||
public int size = 100;
|
||||
@JsonProperty(ScatterplotFacet.DOT)
|
||||
double dot = 100;
|
||||
@JsonProperty(ScatterplotFacet.DIM_X)
|
||||
@JsonIgnore
|
||||
public int dim_x = ScatterplotFacet.LIN;
|
||||
@JsonProperty(ScatterplotFacet.DIM_Y)
|
||||
@JsonIgnore
|
||||
public int dim_y = ScatterplotFacet.LIN;
|
||||
@JsonProperty(ScatterplotFacet.ROTATION)
|
||||
public int rotation = ScatterplotFacet.NO_ROTATION;
|
||||
@ -119,6 +120,26 @@ public class GetScatterplotCommand extends Command {
|
||||
public String columnName_y = "";
|
||||
@JsonProperty(ScatterplotFacet.Y_EXPRESSION)
|
||||
public String expression_y = "value";
|
||||
|
||||
@JsonProperty(ScatterplotFacet.DIM_X)
|
||||
public String getDimX() {
|
||||
return dim_x == ScatterplotFacet.LIN ? "lin" : "log";
|
||||
}
|
||||
|
||||
@JsonProperty(ScatterplotFacet.DIM_Y)
|
||||
public String getDimY() {
|
||||
return dim_y == ScatterplotFacet.LIN ? "lin" : "log";
|
||||
}
|
||||
|
||||
@JsonProperty(ScatterplotFacet.DIM_X)
|
||||
public void setDimX(String dim) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(OutputStream output, Project project, Engine engine, PlotterConfig o) throws IOException {
|
||||
|
@ -0,0 +1,70 @@
|
||||
package com.google.refine.commands.browsing;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.Assert;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.google.refine.browsing.facets.ScatterplotFacet;
|
||||
import com.google.refine.commands.Command;
|
||||
import com.google.refine.commands.browsing.GetScatterplotCommand;
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
|
||||
public class ScatterplotDrawCommandTests {
|
||||
protected HttpServletRequest request = null;
|
||||
protected HttpServletResponse response = null;
|
||||
protected StringWriter writer = null;
|
||||
protected Command command = null;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
request = mock(HttpServletRequest.class);
|
||||
response = mock(HttpServletResponse.class);
|
||||
command = new GetScatterplotCommand();
|
||||
writer = new StringWriter();
|
||||
try {
|
||||
when(response.getWriter()).thenReturn(new PrintWriter(writer));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String configJson = "{"
|
||||
+ "\"name\":\"a (x) vs. b (y)\","
|
||||
+ "\"cx\":\"a\","
|
||||
+ "\"cy\":\"b\","
|
||||
+ "\"l\":150,"
|
||||
+ "\"ex\":\"value\","
|
||||
+ "\"ey\":\"value\","
|
||||
+ "\"dot\":0.8,"
|
||||
+ "\"dim_x\":\"log\","
|
||||
+ "\"dim_y\":\"lin\","
|
||||
+ "\"type\":\"scatterplot\","
|
||||
+ "\"from_x\":1,"
|
||||
+ "\"to_x\":2,"
|
||||
+ "\"from_y\":3,"
|
||||
+ "\"to_y\":4,"
|
||||
+ "\"color\":\"ff6a00\""
|
||||
+ "}";
|
||||
|
||||
@Test
|
||||
public void testParseConfig() throws JsonParseException, JsonMappingException, IOException {
|
||||
GetScatterplotCommand.PlotterConfig config = ParsingUtilities.mapper.readValue(configJson, GetScatterplotCommand.PlotterConfig.class);
|
||||
Assert.assertEquals("a", config.columnName_x);
|
||||
Assert.assertEquals("b", config.columnName_y);
|
||||
Assert.assertEquals(ScatterplotFacet.LOG, config.dim_x);
|
||||
Assert.assertEquals(ScatterplotFacet.LIN, config.dim_y);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user