Search in sources :

Example 1 with XYGraphics

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

the class SimpleTimePlot method setDisplayNames.

public void setDisplayNames(List<String> displayNames) {
    this.displayNames = displayNames;
    if (displayNames != null) {
        List<XYGraphics> graphics = getGraphics();
        int i = 0;
        for (XYGraphics graphic : graphics) {
            if (graphic instanceof Line) {
                graphic.setDisplayName(displayNames.get(++i));
            }
        }
    }
}
Also used : Line(com.twosigma.beakerx.chart.xychart.plotitem.Line) XYGraphics(com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics)

Example 2 with XYGraphics

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

the class ChartToJson method serializeXYGraphics.

public static Map<Object, Object> serializeXYGraphics(List<XYGraphics> xyGraphics) {
    List result = new ArrayList();
    for (XYGraphics item : xyGraphics) {
        result.add(toJson(item));
    }
    Map<Object, Object> value = new LinkedHashMap<>();
    value.put(XYChartSerializer.GRAPHICS_LIST, toJsonList(result));
    return value;
}
Also used : ArrayList(java.util.ArrayList) XYGraphics(com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics) List(java.util.List) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with XYGraphics

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

the class MIMEContainerFactory method createMIMEContainersFromObject.

private static List<MIMEContainer> createMIMEContainersFromObject(final Object data) {
    Object input = DisplayerDataMapper.convert(data);
    if (input instanceof DisplayableWidget) {
        ((DisplayableWidget) input).display();
        return HIDDEN_MIME;
    }
    TableDisplay table = getTableDisplay(input);
    if (table != null) {
        table.display();
        return HIDDEN_MIME;
    }
    if (input instanceof Collection) {
        return singletonList(MIMEContainer.Text(collectionToString((Collection<?>) input)));
    }
    if (input instanceof XYGraphics) {
        new Plot().add((XYGraphics) input).display();
        return HIDDEN_MIME;
    }
    if (input instanceof MIMEContainer) {
        return singletonList((MIMEContainer) input);
    }
    return Displayers.display(input).entrySet().stream().map(item -> new MIMEContainer(item.getKey(), item.getValue())).collect(Collectors.toList());
}
Also used : Displayers(jupyter.Displayers) Plot(com.twosigma.beakerx.chart.xychart.Plot) Iterator(java.util.Iterator) Text(com.twosigma.beakerx.mimetype.MIMEContainer.Text) TableDisplay(com.twosigma.beakerx.table.TableDisplay) Collection(java.util.Collection) MIMEContainer(com.twosigma.beakerx.mimetype.MIMEContainer) HIDDEN(com.twosigma.beakerx.mimetype.MIMEContainer.HIDDEN) Collectors(java.util.stream.Collectors) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) XYGraphics(com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics) DisplayableWidget(com.twosigma.beakerx.widget.DisplayableWidget) Map(java.util.Map) Kernel(com.twosigma.beakerx.kernel.Kernel) DisplayableWidget(com.twosigma.beakerx.widget.DisplayableWidget) MIMEContainer(com.twosigma.beakerx.mimetype.MIMEContainer) TableDisplay(com.twosigma.beakerx.table.TableDisplay) Plot(com.twosigma.beakerx.chart.xychart.Plot) XYGraphics(com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics) Collection(java.util.Collection)

Example 4 with XYGraphics

use of com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics 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)

Aggregations

XYGraphics (com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics)4 Line (com.twosigma.beakerx.chart.xychart.plotitem.Line)2 List (java.util.List)2 Color (com.twosigma.beakerx.chart.Color)1 Plot (com.twosigma.beakerx.chart.xychart.Plot)1 Points (com.twosigma.beakerx.chart.xychart.plotitem.Points)1 Kernel (com.twosigma.beakerx.kernel.Kernel)1 MIMEContainer (com.twosigma.beakerx.mimetype.MIMEContainer)1 HIDDEN (com.twosigma.beakerx.mimetype.MIMEContainer.HIDDEN)1 Text (com.twosigma.beakerx.mimetype.MIMEContainer.Text)1 TableDisplay (com.twosigma.beakerx.table.TableDisplay)1 DisplayableWidget (com.twosigma.beakerx.widget.DisplayableWidget)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Displayers (jupyter.Displayers)1