Search in sources :

Example 1 with TreeMap

use of com.twosigma.beakerx.chart.treemap.TreeMap 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 TreeMap

use of com.twosigma.beakerx.chart.treemap.TreeMap in project beakerx by twosigma.

the class PlotObjectSerializerTest method serializeTreeMap_returnTrue.

@Test
public void serializeTreeMap_returnTrue() throws Exception {
    // when
    boolean result = plotObjectSerializer.writeObject(new TreeMap(), jgen, true);
    // then
    Assertions.assertThat(result).isTrue();
}
Also used : TreeMap(com.twosigma.beakerx.chart.treemap.TreeMap) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 3 with TreeMap

use of com.twosigma.beakerx.chart.treemap.TreeMap in project beakerx by twosigma.

the class TreeMapSerializerTest method initTestStubData.

@Before
public void initTestStubData() throws IOException {
    KernelManager.register(new KernelTest());
    sw = new StringWriter();
    jgen = mapper.getJsonFactory().createJsonGenerator(sw);
    treeMap = new TreeMap(new TreeMapNode("label", 1, new DefaultValue(1.5)));
}
Also used : DefaultValue(net.sf.jtreemap.swing.DefaultValue) StringWriter(java.io.StringWriter) KernelTest(com.twosigma.beakerx.KernelTest) TreeMapNode(net.sf.jtreemap.swing.TreeMapNode) TreeMap(com.twosigma.beakerx.chart.treemap.TreeMap) Before(org.junit.Before)

Example 4 with TreeMap

use of com.twosigma.beakerx.chart.treemap.TreeMap in project beakerx by twosigma.

the class GradientColorProviderTest method initStubData.

@Before
public void initStubData() {
    KernelManager.register(new KernelTest());
    treeMap = new TreeMap();
    treeMap.setRoot(new TreeMapNode("020", 2, new DefaultValue(2)));
    node01 = new TreeMapNode("010", 1, new DefaultValue(1));
}
Also used : DefaultValue(net.sf.jtreemap.swing.DefaultValue) KernelTest(com.twosigma.beakerx.KernelTest) TreeMapNode(net.sf.jtreemap.swing.TreeMapNode) TreeMap(com.twosigma.beakerx.chart.treemap.TreeMap) Before(org.junit.Before)

Aggregations

TreeMap (com.twosigma.beakerx.chart.treemap.TreeMap)4 KernelTest (com.twosigma.beakerx.KernelTest)3 TreeMapNode (net.sf.jtreemap.swing.TreeMapNode)3 DefaultValue (net.sf.jtreemap.swing.DefaultValue)2 Before (org.junit.Before)2 Color (com.twosigma.beakerx.chart.Color)1 IToolTipBuilder (com.twosigma.beakerx.chart.treemap.util.IToolTipBuilder)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1