Search in sources :

Example 6 with Color

use of com.twosigma.beakerx.chart.Color in project beakerx by twosigma.

the class ColorUtilsTest method callInterpolateColorWithGreenBlueColors_returnBeakerColorWithRGB.

@Test
public void callInterpolateColorWithGreenBlueColors_returnBeakerColorWithRGB() {
    // when
    Color color = ColorUtils.interpolateColor(java.awt.Color.GREEN, java.awt.Color.BLUE, 0.1f);
    // then
    Assertions.assertThat(color.getRGB()).isNotZero();
}
Also used : Color(com.twosigma.beakerx.chart.Color) Test(org.junit.Test)

Example 7 with Color

use of com.twosigma.beakerx.chart.Color in project beakerx by twosigma.

the class ColorDeserializerTest method deserialize_resultObjectHasColor.

@Test
public void deserialize_resultObjectHasColor() throws Exception {
    // given
    ObjectMapper mapper = new ObjectMapper();
    JsonNode actualObj = mapper.readTree(json);
    ColorDeserializer deserializer = new ColorDeserializer(new BasicObjectSerializer());
    // when
    Color color = (Color) deserializer.deserialize(actualObj, mapper);
    // then
    Assertions.assertThat(color).isNotNull();
    Assertions.assertThat(color.getRGB()).isEqualTo(Color.GREEN.getRGB());
}
Also used : Color(com.twosigma.beakerx.chart.Color) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 8 with Color

use of com.twosigma.beakerx.chart.Color 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 9 with Color

use of com.twosigma.beakerx.chart.Color in project beakerx by twosigma.

the class TableDisplayTest method shouldSendCommMsgWhenAddValueHighlighterClosureForColumnChange.

@Test
public void shouldSendCommMsgWhenAddValueHighlighterClosureForColumnChange() throws Exception {
    // when
    tableDisplay.addCellHighlighter(new ClosureTest() {

        @Override
        public Color call(Object row, Object col, Object tbl) {
            return ((int) row % 2 == 0) ? Color.GREEN : Color.BLUE;
        }

        @Override
        public int getMaximumNumberOfParameters() {
            return 3;
        }
    });
    // then
    List actual = getValueAsList(getModelUpdate(), CELL_HIGHLIGHTERS);
    Map column = (Map) actual.get(0);
    assertThat(column.get(ValueHighlighterSerializer.TYPE)).isEqualTo(ValueHighlighter.class.getSimpleName());
}
Also used : Color(com.twosigma.beakerx.chart.Color) List(java.util.List) ArrayList(java.util.ArrayList) ValueHighlighter(com.twosigma.beakerx.table.highlight.ValueHighlighter) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 10 with Color

use of com.twosigma.beakerx.chart.Color in project beakerx by twosigma.

the class TableDisplayTest method shouldSendCommMsgWhenSetFontColorProviderClojureChange.

@Test
public void shouldSendCommMsgWhenSetFontColorProviderClojureChange() throws Exception {
    // when
    tableDisplay.setFontColorProvider(new ClosureTest() {

        @Override
        public Color call(Object row, Object col, Object tbl) {
            return ((int) row % 2 == 0) ? Color.GREEN : Color.BLUE;
        }

        @Override
        public int getMaximumNumberOfParameters() {
            return 3;
        }
    });
    // then
    LinkedHashMap model = getModelUpdate();
    assertThat(model.size()).isEqualTo(1);
    List colors = getValueAsList(model, FONT_COLOR);
    List actual = (List) colors.get(0);
    assertThat(actual.get(0).toString()).startsWith("#");
}
Also used : Color(com.twosigma.beakerx.chart.Color) List(java.util.List) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Aggregations

Color (com.twosigma.beakerx.chart.Color)17 Test (org.junit.Test)11 LinkedHashMap (java.util.LinkedHashMap)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 KernelTest (com.twosigma.beakerx.KernelTest)6 HashMap (java.util.HashMap)6 ValueHighlighter (com.twosigma.beakerx.table.highlight.ValueHighlighter)5 Map (java.util.Map)4 TableDisplayToJson.serializeFontColor (com.twosigma.beakerx.table.TableDisplayToJson.serializeFontColor)2 ThreeColorHeatmapHighlighter (com.twosigma.beakerx.table.highlight.ThreeColorHeatmapHighlighter)2 Arrays.asList (java.util.Arrays.asList)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AbstractChartTest (com.twosigma.beakerx.chart.AbstractChartTest)1 TreeMap (com.twosigma.beakerx.chart.treemap.TreeMap)1 IToolTipBuilder (com.twosigma.beakerx.chart.treemap.util.IToolTipBuilder)1 Line (com.twosigma.beakerx.chart.xychart.plotitem.Line)1 Points (com.twosigma.beakerx.chart.xychart.plotitem.Points)1 XYGraphics (com.twosigma.beakerx.chart.xychart.plotitem.XYGraphics)1