Search in sources :

Example 11 with LineChart

use of com.android.tools.adtui.chart.linechart.LineChart in project android by JetBrains.

the class NetworkMonitorView method populateUi.

@Override
protected void populateUi(JPanel container, Choreographer choreographer) {
    container.setLayout(new TabularLayout("*", "*"));
    Range viewRange = getMonitor().getTimeline().getViewRange();
    Range dataRange = getMonitor().getTimeline().getDataRange();
    final JLabel label = new JLabel(getMonitor().getName());
    label.setBorder(MONITOR_LABEL_PADDING);
    label.setVerticalAlignment(JLabel.TOP);
    Range leftYRange = new Range(0, 4);
    final JPanel axisPanel = new JBPanel(new BorderLayout());
    axisPanel.setOpaque(false);
    AxisComponent.Builder builder = new AxisComponent.Builder(leftYRange, BANDWIDTH_AXIS_FORMATTER_L1, AxisComponent.AxisOrientation.RIGHT).showAxisLine(false).showMax(true).showUnitAtMax(true).setMarkerLengths(MARKER_LENGTH, MARKER_LENGTH).clampToMajorTicks(true).setMargins(0, Y_AXIS_TOP_MARGIN);
    final AxisComponent leftAxis = builder.build();
    axisPanel.add(leftAxis, BorderLayout.WEST);
    final JPanel lineChartPanel = new JBPanel(new BorderLayout());
    lineChartPanel.setOpaque(false);
    lineChartPanel.setBorder(BorderFactory.createEmptyBorder(Y_AXIS_TOP_MARGIN, 0, 0, 0));
    final LineChart lineChart = new LineChart();
    RangedContinuousSeries rxSeries = new RangedContinuousSeries(NetworkTrafficDataSeries.Type.BYTES_RECEIVED.getLabel(), viewRange, leftYRange, getMonitor().getSpeedSeries(NetworkTrafficDataSeries.Type.BYTES_RECEIVED));
    RangedContinuousSeries txSeries = new RangedContinuousSeries(NetworkTrafficDataSeries.Type.BYTES_SENT.getLabel(), viewRange, leftYRange, getMonitor().getSpeedSeries(NetworkTrafficDataSeries.Type.BYTES_SENT));
    LineConfig receivedConfig = new LineConfig(ProfilerColors.NETWORK_RECEIVING_COLOR);
    lineChart.addLine(rxSeries, receivedConfig);
    LineConfig sentConfig = new LineConfig(ProfilerColors.NETWORK_SENDING_COLOR);
    lineChart.addLine(txSeries, sentConfig);
    lineChartPanel.add(lineChart, BorderLayout.CENTER);
    final LegendComponent legend = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, LEGEND_UPDATE_FREQUENCY_MS);
    ArrayList<LegendRenderData> legendData = new ArrayList<>();
    legendData.add(lineChart.createLegendRenderData(rxSeries, BANDWIDTH_AXIS_FORMATTER_L1, dataRange));
    legendData.add(lineChart.createLegendRenderData(txSeries, BANDWIDTH_AXIS_FORMATTER_L1, dataRange));
    legend.setLegendData(legendData);
    final JPanel legendPanel = new JBPanel(new BorderLayout());
    legendPanel.setOpaque(false);
    legendPanel.add(label, BorderLayout.WEST);
    legendPanel.add(legend, BorderLayout.EAST);
    choreographer.register(lineChart);
    choreographer.register(leftAxis);
    choreographer.register(legend);
    container.add(legendPanel, new TabularLayout.Constraint(0, 0));
    container.add(leftAxis, new TabularLayout.Constraint(0, 0));
    container.add(lineChartPanel, new TabularLayout.Constraint(0, 0));
    container.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            getMonitor().expand();
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) ArrayList(java.util.ArrayList) MouseAdapter(java.awt.event.MouseAdapter) Range(com.android.tools.adtui.model.Range) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) JBPanel(com.intellij.ui.components.JBPanel) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Aggregations

LineChart (com.android.tools.adtui.chart.linechart.LineChart)11 Range (com.android.tools.adtui.model.Range)8 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)8 LineConfig (com.android.tools.adtui.chart.linechart.LineConfig)7 JBPanel (com.intellij.ui.components.JBPanel)6 MouseAdapter (java.awt.event.MouseAdapter)6 MouseEvent (java.awt.event.MouseEvent)6 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 java.awt (java.awt)4 javax.swing (javax.swing)4 com.android.tools.adtui (com.android.tools.adtui)3 AdtUiUtils (com.android.tools.adtui.common.AdtUiUtils)3 ImmutableList (com.intellij.util.containers.ImmutableList)3 List (java.util.List)3 AxisComponent (com.android.tools.adtui.AxisComponent)2 LegendComponent (com.android.tools.adtui.LegendComponent)2 TabularLayout (com.android.tools.adtui.TabularLayout)2 DurationDataRenderer (com.android.tools.adtui.chart.linechart.DurationDataRenderer)2 OverlayComponent (com.android.tools.adtui.chart.linechart.OverlayComponent)2