Search in sources :

Example 1 with ValuedTreeNode

use of com.android.tools.adtui.ValuedTreeNode in project android by JetBrains.

the class SunburstChart method updateStructure.

private boolean updateStructure(Slice slice, ValuedTreeNode node, boolean hasSiblings) {
    if (node == null) {
        slice.depth = Choreographer.lerp(slice.depth, hasSiblings ? slice.depth : 0.0f, 0.99f, mFrameLength);
        slice.value = Choreographer.lerp(slice.value, hasSiblings ? 0.0f : slice.value, 0.99f, mFrameLength);
    } else {
        slice.depth = Choreographer.lerp(slice.depth, node.getParent() == null ? 0.0f : 1.0f, 0.99f, mFrameLength);
        slice.value = Choreographer.lerp(slice.value, getFraction(node), 0.99f, mFrameLength);
    }
    slice.node = node;
    int last = -1;
    int slices = slice.getChildrenCount();
    int nodes = node == null ? 0 : node.getChildCount();
    for (int i = 0; i < slices; i++) {
        Slice childSlice = slice.getChild(i);
        ValuedTreeNode childNode = i < nodes ? getChildAt(node, i) : null;
        if (updateStructure(childSlice, childNode, nodes > 0)) {
            last = i;
        }
    }
    // Test neighbours with the same color:
    int c = slices > 0 ? slice.getChild(0).color : ((slice.color + (int) (Math.random() * COLORS.length - 1) + 1) % COLORS.length);
    for (int i = slices; i < nodes; i++) {
        ValuedTreeNode childNode = getChildAt(node, i);
        Slice childSlice = new Slice(slices > 0 ? 0.0f : getFraction(childNode));
        childSlice.color = c;
        childSlice.depth = slices > 0 ? 1.0f : 0.0f;
        slice.addChild(childSlice);
        if (updateStructure(childSlice, childNode, nodes > 0)) {
            last = i;
        }
    }
    if (last + 1 < slice.getChildrenCount()) {
        slice.clearSublist(last + 1, slice.getChildrenCount());
    }
    return node != null || (slice.depth > 0.00001f && slice.value > 0.00001f) || last >= 0;
}
Also used : ValuedTreeNode(com.android.tools.adtui.ValuedTreeNode)

Example 2 with ValuedTreeNode

use of com.android.tools.adtui.ValuedTreeNode in project android by JetBrains.

the class SunburstVisualTest method populateUi.

@Override
protected void populateUi(@NotNull JPanel panel) {
    JPanel controls = VisualTest.createControlledPane(panel, mSunburst);
    final JLabel info = new JLabel("<No information yet>");
    panel.add(info, BorderLayout.SOUTH);
    controls.add(VisualTest.createVariableSlider("Gap", 0, 200, new VisualTests.Value() {

        @Override
        public void set(int v) {
            mSunburst.setGap(v);
        }

        @Override
        public int get() {
            return (int) mSunburst.getGap();
        }
    }));
    final JPanel sizeSlider = VisualTest.createVariableSlider("Size", 0, 200, new VisualTests.Value() {

        @Override
        public void set(int v) {
            mSunburst.setSliceWidth(v);
        }

        @Override
        public int get() {
            return (int) mSunburst.getSliceWidth();
        }
    });
    controls.add(sizeSlider);
    controls.add(VisualTest.createVariableSlider("Angle", 0, 360, new VisualTests.Value() {

        @Override
        public void set(int v) {
            mSunburst.setAngle(v);
        }

        @Override
        public int get() {
            return (int) mSunburst.getAngle();
        }
    }));
    controls.add(VisualTest.createVariableSlider("Start", 0, 360, new VisualTests.Value() {

        @Override
        public void set(int v) {
            mSunburst.setStart(v);
        }

        @Override
        public int get() {
            return (int) mSunburst.getStart();
        }
    }));
    controls.add(VisualTest.createVariableSlider("Fixed", 1, 100, new VisualTests.Value() {

        @Override
        public void set(int v) {
            mSunburst.setFixed(v);
        }

        @Override
        public int get() {
            return (int) mSunburst.getFixed();
        }
    }));
    controls.add(VisualTest.createVariableSlider("Separator", 0, 100, new VisualTests.Value() {

        @Override
        public void set(int v) {
            mSunburst.setSeparator(v);
        }

        @Override
        public int get() {
            return (int) mSunburst.getSeparator();
        }
    }));
    controls.add(VisualTest.createButton("Generate", new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            generateLayoutData((DataNode) mSunburst.getData(), 5);
        }
    }));
    controls.add(VisualTest.createButton("Tree A", new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            DataNode g = new DataNode();
            g.addDataNode(createTree(1));
            g.addDataNode(createValue());
            g.addDataNode(createTree(1));
            g.addDataNode(createValue());
            g.addDataNode(createTree(0));
            mSunburst.setData(g);
        }
    }));
    controls.add(VisualTest.createButton("Tree B", new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            DataNode g = new DataNode();
            g.addDataNode(createValue());
            g.addDataNode(createValue());
            g.addDataNode(createTree(0));
            mSunburst.setData(g);
        }
    }));
    controls.add(VisualTest.createButton("Value", new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            DataNode g = new DataNode();
            g.addDataNode(new DataNode(1, (int) (Math.random() * 50)));
            mSunburst.setData(g);
        }
    }));
    controls.add(VisualTest.createCheckbox("Auto size", new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent itemEvent) {
            final boolean enableAutoSize = itemEvent.getStateChange() == ItemEvent.SELECTED;
            mSunburst.setAutoSize(enableAutoSize);
            // If auto size is enabled, size shouldn't be controlled by slider
            // sizeSlider is a JPanel and its first child is a JSlider
            Accessible sliderAccessible = SwingUtilities.getAccessibleChild(sizeSlider, 0);
            if (sliderAccessible instanceof JSlider) {
                JSlider slider = (JSlider) sliderAccessible;
                slider.setEnabled(!enableAutoSize);
                // If disabling auto size, set slider width to current slice width
                if (!enableAutoSize) {
                    slider.setValue((int) mSunburst.getSliceWidth());
                }
            }
        }
    }));
    controls.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
    mSunburst.addSelectionListener(new SunburstChart.SliceSelectionListener() {

        @Override
        public void valueChanged(SunburstChart.SliceSelectionEvent e) {
            ValuedTreeNode node = e.getNode();
            info.setText(node == null ? "<No selection>" : String.format("Value %d Count %d", node.getValue(), node.getCount()));
        }
    });
}
Also used : ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) SunburstChart(com.android.tools.adtui.chart.SunburstChart) ActionListener(java.awt.event.ActionListener) ValuedTreeNode(com.android.tools.adtui.ValuedTreeNode) ItemListener(java.awt.event.ItemListener) Accessible(javax.accessibility.Accessible)

Example 3 with ValuedTreeNode

use of com.android.tools.adtui.ValuedTreeNode in project android by JetBrains.

the class AllocationsView method valueChanged.

@Override
public void valueChanged(SunburstChart.SliceSelectionEvent e) {
    ValuedTreeNode node = e == null ? null : e.getNode();
    HtmlBuilder builder = new HtmlBuilder();
    builder.openHtmlBody();
    if (node == null) {
        node = myTreeNode;
    }
    builder.add("Total allocations:").addNbsp().addBold(Integer.toString(node.getCount())).newline().add("Total size:").addNbsp().addBold(StringUtil.formatFileSize(node.getValue())).newline().newline();
    if (node instanceof AbstractTreeNode) {
        TreeNode[] path = myTreeModel.getPathToRoot(node);
        myInfoTableModel.setRowCount(path.length);
        // Start at 1 to avoid adding the root node.
        for (int i = 1; i < path.length; i++) {
            myInfoTableModel.setValueAt(path[i], i - 1, 0);
        }
        myInfoTableModel.fireTableDataChanged();
    }
    builder.closeHtmlBody();
    myInfoLabel.setText(builder.getHtml());
}
Also used : TreeNode(javax.swing.tree.TreeNode) ValuedTreeNode(com.android.tools.adtui.ValuedTreeNode) HtmlBuilder(com.android.utils.HtmlBuilder) ValuedTreeNode(com.android.tools.adtui.ValuedTreeNode)

Aggregations

ValuedTreeNode (com.android.tools.adtui.ValuedTreeNode)3 SunburstChart (com.android.tools.adtui.chart.SunburstChart)1 HtmlBuilder (com.android.utils.HtmlBuilder)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 Accessible (javax.accessibility.Accessible)1 TreeNode (javax.swing.tree.TreeNode)1