Search in sources :

Example 1 with Points

use of com.twosigma.beakerx.chart.xychart.plotitem.Points in project beakerx by twosigma.

the class GroovyEvaluatorChartTest method parsePlotWithPointsScript_returnPlotObjectWithPoints.

@Test
public void parsePlotWithPointsScript_returnPlotObjectWithPoints() {
    // when
    Object result = parseClassFromScript("def plot = new Plot();\n" + "def y1 = [6, 7, 12, 11, 8, 14]\n" + "plot << new Points(y: y1)");
    // then
    Assertions.assertThat(result instanceof Plot).isTrue();
    Plot plot = (Plot) result;
    Assertions.assertThat(plot.getGraphics()).isNotEmpty();
    Assertions.assertThat(plot.getGraphics().get(0) instanceof Points).isTrue();
}
Also used : Points(com.twosigma.beakerx.chart.xychart.plotitem.Points) TimePlot(com.twosigma.beakerx.chart.xychart.TimePlot) SimpleTimePlot(com.twosigma.beakerx.chart.xychart.SimpleTimePlot) CombinedPlot(com.twosigma.beakerx.chart.xychart.CombinedPlot) Plot(com.twosigma.beakerx.chart.xychart.Plot) CategoryPlot(com.twosigma.beakerx.chart.categoryplot.CategoryPlot) NanoPlot(com.twosigma.beakerx.chart.xychart.NanoPlot) Test(org.junit.Test)

Example 2 with Points

use of com.twosigma.beakerx.chart.xychart.plotitem.Points in project beakerx by twosigma.

the class PointsSerializerTest method initTestStubData.

@Before
public void initTestStubData() throws IOException {
    sw = new StringWriter();
    jgen = mapper.getJsonFactory().createJsonGenerator(sw);
    points = new Points();
    points.setX(Arrays.asList(1, 2, 3));
    points.setY(Arrays.asList(1, 2, 3));
}
Also used : Points(com.twosigma.beakerx.chart.xychart.plotitem.Points) StringWriter(java.io.StringWriter) Before(org.junit.Before)

Example 3 with Points

use of com.twosigma.beakerx.chart.xychart.plotitem.Points in project beakerx by twosigma.

the class SimpleTimePlot method reinitialize.

private void reinitialize() {
    List<XYGraphics> graphics = getGraphics();
    filter(graphics, new Predicate<XYGraphics>() {

        public boolean test(XYGraphics graphic) {
            return !(graphic instanceof Line || graphic instanceof Points);
        }
    });
    List<Object> xs = new ArrayList<>();
    List<List<Number>> yss = new ArrayList<>();
    Set<String> dataColumnsNames = new HashSet<>();
    if (data != null && columns != null) {
        for (Map<String, Object> row : data) {
            dataColumnsNames.addAll(row.keySet());
            xs.add(getNumberForTimeColumn(row.get(timeColumn)));
            for (int i = 0; i < columns.size(); i++) {
                String column = columns.get(i);
                if (i >= yss.size()) {
                    yss.add(new ArrayList<Number>());
                }
                yss.get(i).add(getNumberForTimeColumn(row.get(column)));
            }
        }
        final HashSet<String> columnsWithoutData = getColumnsWithoutData(dataColumnsNames);
        if (!columnsWithoutData.isEmpty()) {
            throw new IllegalArgumentException(String.format("Chart data not found for columns: %s", columnsWithoutData));
        }
        List<Color> colors = getChartColors();
        for (int i = 0; i < yss.size(); i++) {
            List<Number> ys = yss.get(i);
            if (displayLines) {
                Line line = new Line();
                line.setX(xs);
                line.setY(ys);
                if (displayNames != null && i < displayNames.size()) {
                    line.setDisplayName(displayNames.get(i));
                } else {
                    line.setDisplayName(columns.get(i));
                }
                if (i < colors.size()) {
                    line.setColor(colors.get(i));
                }
                add(line);
            }
            if (displayPoints) {
                Points points = new Points();
                points.setX(xs);
                points.setY(ys);
                if (displayNames != null && i < displayNames.size()) {
                    points.setDisplayName(displayNames.get(i));
                } else {
                    points.setDisplayName(columns.get(i));
                }
                if (i < colors.size()) {
                    points.setColor(colors.get(i));
                }
                add(points);
            }
        }
    }
}
Also used : Color(com.twosigma.beakerx.chart.Color) XYGraphics(com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics) Line(com.twosigma.beakerx.chart.xychart.plotitem.Line) Points(com.twosigma.beakerx.chart.xychart.plotitem.Points)

Example 4 with Points

use of com.twosigma.beakerx.chart.xychart.plotitem.Points in project beakerx by twosigma.

the class NanoPlotTest method initStubData.

@Before
public void initStubData() {
    BigInteger val1 = new BigInteger("12345678901234567891000");
    BigInteger val2 = new BigInteger("12345678901234567892000");
    points = new Points();
    points.setX(Arrays.asList(val1, val2));
    points.setY(Arrays.asList(2, 3));
    line = new Line();
    line.setX(Arrays.asList(val1, val1));
    line.setY(Arrays.asList(2, 3));
}
Also used : Line(com.twosigma.beakerx.chart.xychart.plotitem.Line) Points(com.twosigma.beakerx.chart.xychart.plotitem.Points) BigInteger(java.math.BigInteger) Before(org.junit.Before)

Example 5 with Points

use of com.twosigma.beakerx.chart.xychart.plotitem.Points in project beakerx by twosigma.

the class GroovyEvaluatorChartTest method parsePlotWithCircleShapePointsScript_returnPlotObjectWithCircleShapePoints.

@Test
public void parsePlotWithCircleShapePointsScript_returnPlotObjectWithCircleShapePoints() {
    // when
    Object result = parseClassFromScript("def plot = new Plot();\n" + "def y1 = [1.5, 1, 6, 5, 2, 8]\n" + "plot << new Points(y: y1, shape: ShapeType.CIRCLE)");
    // then
    Assertions.assertThat(result instanceof Plot).isTrue();
    Plot plot = (Plot) result;
    Assertions.assertThat(plot.getGraphics()).isNotEmpty();
    Assertions.assertThat(((Points) plot.getGraphics().get(0)).getShape()).isEqualTo(ShapeType.CIRCLE);
}
Also used : Points(com.twosigma.beakerx.chart.xychart.plotitem.Points) TimePlot(com.twosigma.beakerx.chart.xychart.TimePlot) SimpleTimePlot(com.twosigma.beakerx.chart.xychart.SimpleTimePlot) CombinedPlot(com.twosigma.beakerx.chart.xychart.CombinedPlot) Plot(com.twosigma.beakerx.chart.xychart.Plot) CategoryPlot(com.twosigma.beakerx.chart.categoryplot.CategoryPlot) NanoPlot(com.twosigma.beakerx.chart.xychart.NanoPlot) Test(org.junit.Test)

Aggregations

Points (com.twosigma.beakerx.chart.xychart.plotitem.Points)5 CategoryPlot (com.twosigma.beakerx.chart.categoryplot.CategoryPlot)2 CombinedPlot (com.twosigma.beakerx.chart.xychart.CombinedPlot)2 NanoPlot (com.twosigma.beakerx.chart.xychart.NanoPlot)2 Plot (com.twosigma.beakerx.chart.xychart.Plot)2 SimpleTimePlot (com.twosigma.beakerx.chart.xychart.SimpleTimePlot)2 TimePlot (com.twosigma.beakerx.chart.xychart.TimePlot)2 Line (com.twosigma.beakerx.chart.xychart.plotitem.Line)2 Before (org.junit.Before)2 Test (org.junit.Test)2 Color (com.twosigma.beakerx.chart.Color)1 XYGraphics (com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics)1 StringWriter (java.io.StringWriter)1 BigInteger (java.math.BigInteger)1