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