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);
}
}
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();
}
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);
}
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));
}
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);
}
}
Aggregations