Search in sources :

Example 1 with ValueHighlighter

use of com.twosigma.beakerx.table.highlight.ValueHighlighter 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 2 with ValueHighlighter

use of com.twosigma.beakerx.table.highlight.ValueHighlighter in project beakerx by twosigma.

the class TableDisplayTest method shouldSendCommMsgWhenAddValueHighlighterForColumnChange.

@Test
public void shouldSendCommMsgWhenAddValueHighlighterForColumnChange() throws Exception {
    // given;
    ValueHighlighter highlighter = new ValueHighlighter(COL_1, Arrays.asList(new Color(247, 106, 106)));
    // when
    tableDisplay.addCellHighlighter(highlighter);
    // then
    assertThat(tableDisplay.getCellHighlighters().get(0)).isEqualTo(highlighter);
    LinkedHashMap model = getModelUpdate();
    assertThat(model.size()).isEqualTo(1);
    List actual = getValueAsList(model, CELL_HIGHLIGHTERS);
    Map column = (Map) actual.get(0);
    assertThat(column.get(ValueHighlighterSerializer.TYPE)).isEqualTo(ValueHighlighter.class.getSimpleName());
    assertThat(column.get(ValueHighlighterSerializer.COL_NAME)).isEqualTo(COL_1);
    assertThat(column.get(ValueHighlighterSerializer.COLORS)).isNotNull();
}
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) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 3 with ValueHighlighter

use of com.twosigma.beakerx.table.highlight.ValueHighlighter in project beakerx by twosigma.

the class TableDisplayClosureTest method addCellHighlighterClosure_shouldFormatCellColors.

@Test
public void addCellHighlighterClosure_shouldFormatCellColors() 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
    ValueHighlighter highlighter = (ValueHighlighter) tableDisplay.getCellHighlighters().get(0);
    Assertions.assertThat(highlighter.getColors().get(0)).isEqualTo(Color.GREEN);
    Assertions.assertThat(highlighter.getColors().get(1)).isEqualTo(Color.BLUE);
}
Also used : Color(com.twosigma.beakerx.chart.Color) ValueHighlighter(com.twosigma.beakerx.table.highlight.ValueHighlighter) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 4 with ValueHighlighter

use of com.twosigma.beakerx.table.highlight.ValueHighlighter in project beakerx by twosigma.

the class ValueHighlighterSerializerTest method setUp.

@Before
public void setUp() throws Exception {
    KernelManager.register(new KernelTest());
    sw = new StringWriter();
    jgen = mapper.getFactory().createGenerator(sw);
    valueHighlighter = new ValueHighlighter("a", Arrays.asList(Color.BLACK, Color.BLUE));
}
Also used : StringWriter(java.io.StringWriter) KernelTest(com.twosigma.beakerx.KernelTest) ValueHighlighter(com.twosigma.beakerx.table.highlight.ValueHighlighter) Before(org.junit.Before)

Example 5 with ValueHighlighter

use of com.twosigma.beakerx.table.highlight.ValueHighlighter in project beakerx by twosigma.

the class TableDisplay method addCellHighlighter.

public void addCellHighlighter(Object closure) {
    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++) {
                Object[] params = new Object[] { rowInd, colInd, this };
                Color color = (Color) runClosure(closure, params);
                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)

Aggregations

ValueHighlighter (com.twosigma.beakerx.table.highlight.ValueHighlighter)5 Color (com.twosigma.beakerx.chart.Color)4 KernelTest (com.twosigma.beakerx.KernelTest)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 TableDisplayToJson.serializeFontColor (com.twosigma.beakerx.table.TableDisplayToJson.serializeFontColor)2 Arrays.asList (java.util.Arrays.asList)2 Test (org.junit.Test)2 StringWriter (java.io.StringWriter)1 Map (java.util.Map)1 Before (org.junit.Before)1