Search in sources :

Example 1 with Color

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

the class TreeMapSerializer method serialize.

@Override
public void serialize(final TreeMap treeMap, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
    TreeMapNode root = treeMap.getRoot();
    process(root, new Visitor<TreeMapNode>() {

        @Override
        public void visit(TreeMapNode node) {
            Object userObject = node.getUserObject();
            Map<String, Object> values;
            if (userObject instanceof Map) {
                values = (Map<String, Object>) userObject;
                if (node.isLeaf()) {
                    Color color = treeMap.getColorProvider().getColor(node);
                    values.put("color", toHex(color));
                    IToolTipBuilder toolTipBuilder = treeMap.getToolTipBuilder();
                    if (toolTipBuilder != null) {
                        values.put(TOOLTIP, toolTipBuilder.getToolTip(node));
                    } else {
                        values.put(TOOLTIP, values.get("label"));
                    }
                }
                node.setUserObject(values);
            } else {
                values = new HashMap<>();
                values.put("label", userObject);
                IToolTipBuilder toolTipBuilder = treeMap.getToolTipBuilder();
                if (toolTipBuilder != null) {
                    values.put(TOOLTIP, toolTipBuilder.getToolTip(node));
                } else {
                    values.put(TOOLTIP, userObject);
                }
            }
            if (node.isLeaf()) {
                Color color = treeMap.getColorProvider().getColor(node);
                values.put("color", toHex(color));
            }
            node.setUserObject(values);
        }
    });
    jgen.writeStartObject();
    serialize(treeMap, jgen);
    if (root != null)
        jgen.writeObjectField(GRAPHICS_LIST, root);
    if (treeMap.getMode() != null)
        jgen.writeObjectField(MODE, treeMap.getMode().getJsName());
    if (treeMap.getSticky() != null)
        jgen.writeObjectField(STICKY, treeMap.getSticky());
    if (treeMap.getRatio() != null)
        jgen.writeObjectField(RATIO, treeMap.getRatio());
    if (treeMap.getRound() != null)
        jgen.writeObjectField(ROUND, treeMap.getRound());
    jgen.writeObjectField(VALUE_ACCESSOR, treeMap.getValueAccessor());
    jgen.writeEndObject();
}
Also used : IToolTipBuilder(com.twosigma.beakerx.chart.treemap.util.IToolTipBuilder) HashMap(java.util.HashMap) Color(com.twosigma.beakerx.chart.Color) TreeMapNode(net.sf.jtreemap.swing.TreeMapNode) TreeMap(com.twosigma.beakerx.chart.treemap.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Color

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

the class ConstantBandSerializer method serialize.

@Override
public void serialize(ConstantBand constantBand, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException {
    jgen.writeStartObject();
    boolean isNanoPlot = NanoPlot.isNanoPlotClass(constantBand.getPlotType());
    jgen.writeObjectField(TYPE, SerializerUtil.getTypeName(constantBand));
    jgen.writeObjectField("x", isNanoPlot ? processLargeNumbers(constantBand.getX()) : constantBand.getX());
    jgen.writeObjectField("y", constantBand.getY());
    jgen.writeObjectField("visible", constantBand.getVisible());
    jgen.writeObjectField("yAxis", constantBand.getYAxis());
    if (constantBand.getColor() == null) {
        jgen.writeObjectField("color", new Color(0, 127, 255, 127));
    } else {
        jgen.writeObjectField("color", constantBand.getColor());
    }
    jgen.writeEndObject();
}
Also used : Color(com.twosigma.beakerx.chart.Color)

Example 3 with Color

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

the class TableDisplayTest method shouldSendCommMsgWhenRemoveAllCellHighlighters.

@Test
public void shouldSendCommMsgWhenRemoveAllCellHighlighters() throws Exception {
    // given;
    TableDisplayCellHighlighter uniqueEntriesHighlighter = TableDisplayCellHighlighter.getUniqueEntriesHighlighter(COL_1, TableDisplayCellHighlighter.FULL_ROW);
    TableDisplayCellHighlighter heatmapHighlighter = TableDisplayCellHighlighter.getHeatmapHighlighter(COL_1, 0, 8, Color.ORANGE, Color.PINK);
    ThreeColorHeatmapHighlighter colorHeatmapHighlighter = new ThreeColorHeatmapHighlighter(COL_1, TableDisplayCellHighlighter.SINGLE_COLUMN, 4, 6, 8, new Color(247, 106, 106), new Color(239, 218, 82), new Color(100, 189, 122));
    tableDisplay.addCellHighlighter(uniqueEntriesHighlighter);
    tableDisplay.addCellHighlighter(heatmapHighlighter);
    tableDisplay.addCellHighlighter(colorHeatmapHighlighter);
    kernel.clearMessages();
    // when
    tableDisplay.removeAllCellHighlighters();
    // then
    assertThat(tableDisplay.getCellHighlighters()).isEmpty();
    LinkedHashMap model = getModelUpdate();
    assertThat(model.size()).isEqualTo(1);
    List actual = getValueAsList(model, CELL_HIGHLIGHTERS);
    assertThat(actual).isEmpty();
}
Also used : ThreeColorHeatmapHighlighter(com.twosigma.beakerx.table.highlight.ThreeColorHeatmapHighlighter) TableDisplayCellHighlighter(com.twosigma.beakerx.table.highlight.TableDisplayCellHighlighter) 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)

Example 4 with Color

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

the class TableDisplay method addCellHighlighter.

public void addCellHighlighter(CellHighlighter cellHighlighter) {
    Map<String, List<Color>> colors = new HashMap<>();
    try {
        int rowSize = this.values.get(0).size();
        for (int colInd = 0; colInd < rowSize; colInd++) {
            boolean hasHighlightedValues = false;
            List<Color> columnColors = new ArrayList<>();
            for (int rowInd = 0; rowInd < this.values.size(); rowInd++) {
                Color color = cellHighlighter.apply(rowInd, colInd, this);
                if (color != null) {
                    hasHighlightedValues = true;
                }
                columnColors.add(color);
            }
            if (hasHighlightedValues) {
                addCellHighlighter(new ValueHighlighter(this.columns.get(colInd), columnColors));
            }
        }
    } catch (Throwable e) {
        throw new IllegalArgumentException("Can not set cell highlighter using closure.", e);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Color(com.twosigma.beakerx.chart.Color) TableDisplayToJson.serializeFontColor(com.twosigma.beakerx.table.TableDisplayToJson.serializeFontColor) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ValueHighlighter(com.twosigma.beakerx.table.highlight.ValueHighlighter)

Example 5 with Color

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

the class ColorUtilsTest method callInterpolateColorWithGreenBlueColorsAndFractionIsOne_returnBeakerColorWithBlueValue.

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

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