use of com.twosigma.beakerx.chart.treemap.util.IToolTipBuilder 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.treemap.util.IToolTipBuilder in project beakerx by twosigma.
the class TreeMapTest method setToolTipBuilder_hasToolTipBuilder.
@Test
public void setToolTipBuilder_hasToolTipBuilder() {
// given
treeMap = createWidget();
// when
treeMap.setToolTipBuilder(new IToolTipBuilder() {
@Override
public String getToolTip(TreeMapNode node) {
return "tooltip";
}
});
// then
assertThat(treeMap.getToolTipBuilder()).isNotNull();
LinkedHashMap model = getModelUpdate();
assertThat(model).isNotNull();
}
Aggregations