Search in sources :

Example 6 with RangedContinuousSeries

use of com.android.tools.adtui.model.RangedContinuousSeries in project android by JetBrains.

the class CpuMonitorView 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);
    // Cpu usage is shown as percentages (e.g. 0 - 100) and no range animation is needed.
    Range leftYRange = new Range(0, 100);
    final JPanel axisPanel = new JBPanel(new BorderLayout());
    axisPanel.setOpaque(false);
    AxisComponent.Builder builder = new AxisComponent.Builder(leftYRange, CPU_USAGE_AXIS, 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 cpuSeries = new RangedContinuousSeries("CPU", viewRange, leftYRange, getMonitor().getThisProcessCpuUsage());
    lineChart.addLine(cpuSeries, new LineConfig(ProfilerColors.CPU_USAGE).setFilled(true));
    lineChartPanel.add(lineChart, BorderLayout.CENTER);
    final LegendComponent legend = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, LEGEND_UPDATE_FREQUENCY_MS);
    legend.setLegendData(Collections.singletonList(lineChart.createLegendRenderData(cpuSeries, CPU_USAGE_AXIS, dataRange)));
    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) TabularLayout(com.android.tools.adtui.TabularLayout) MouseAdapter(java.awt.event.MouseAdapter) AxisComponent(com.android.tools.adtui.AxisComponent) 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) LegendComponent(com.android.tools.adtui.LegendComponent) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Example 7 with RangedContinuousSeries

use of com.android.tools.adtui.model.RangedContinuousSeries in project android by JetBrains.

the class MemoryMonitorView 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, 0);
    final JPanel axisPanel = new JBPanel(new BorderLayout());
    axisPanel.setOpaque(false);
    AxisComponent.Builder builder = new AxisComponent.Builder(leftYRange, MEMORY_AXIS_FORMATTER, AxisComponent.AxisOrientation.RIGHT).showAxisLine(false).showMax(true).showUnitAtMax(true).clampToMajorTicks(true).setMarkerLengths(MARKER_LENGTH, MARKER_LENGTH).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 memSeries = new RangedContinuousSeries("Memory", viewRange, leftYRange, getMonitor().getTotalMemory());
    lineChart.addLine(memSeries, new LineConfig(ProfilerColors.MEMORY_TOTAL).setFilled(true));
    lineChartPanel.add(lineChart, BorderLayout.CENTER);
    final LegendComponent legend = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, LEGEND_UPDATE_FREQUENCY_MS);
    legend.setLegendData(Collections.singletonList(lineChart.createLegendRenderData(memSeries, MEMORY_AXIS_FORMATTER, dataRange)));
    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) TabularLayout(com.android.tools.adtui.TabularLayout) MouseAdapter(java.awt.event.MouseAdapter) AxisComponent(com.android.tools.adtui.AxisComponent) 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) LegendComponent(com.android.tools.adtui.LegendComponent) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Example 8 with RangedContinuousSeries

use of com.android.tools.adtui.model.RangedContinuousSeries in project android by JetBrains.

the class NetworkProfilerStageView method buildMonitorUi.

@NotNull
private JPanel buildMonitorUi() {
    StudioProfilers profilers = getStage().getStudioProfilers();
    ProfilerTimeline timeline = profilers.getTimeline();
    Range viewRange = getTimeline().getViewRange();
    Range dataRange = getTimeline().getDataRange();
    EventMonitor events = new EventMonitor(profilers);
    NetworkMonitor monitor = new NetworkMonitor(getStage().getStudioProfilers());
    TabularLayout layout = new TabularLayout("*");
    JPanel panel = new JBPanel(layout);
    panel.setBackground(ProfilerColors.MONITOR_BACKGROUND);
    // The scrollbar can modify the view range - so it should be registered to the Choreographer before all other Animatables
    // that attempts to read the same range instance.
    ProfilerScrollbar sb = new ProfilerScrollbar(getChoreographer(), timeline, panel);
    getChoreographer().register(sb);
    panel.add(sb, new TabularLayout.Constraint(4, 0));
    AxisComponent timeAxis = buildTimeAxis(profilers);
    getChoreographer().register(timeAxis);
    panel.add(timeAxis, new TabularLayout.Constraint(3, 0));
    EventMonitorView eventsView = new EventMonitorView(events);
    JComponent eventsComponent = eventsView.initialize(getChoreographer());
    panel.add(eventsComponent, new TabularLayout.Constraint(0, 0));
    panel.add(new NetworkRadioView(this).getComponent(), new TabularLayout.Constraint(1, 0));
    JPanel monitorPanel = new JBPanel(new TabularLayout("*", "*"));
    monitorPanel.setOpaque(false);
    monitorPanel.setBorder(MONITOR_BORDER);
    final JLabel label = new JLabel(monitor.getName());
    label.setBorder(MONITOR_LABEL_PADDING);
    label.setVerticalAlignment(SwingConstants.TOP);
    Range leftYRange = new Range(0, 4);
    Range rightYRange = new Range(0, 5);
    RangedContinuousSeries receivedSeries = new RangedContinuousSeries(NetworkTrafficDataSeries.Type.BYTES_RECEIVED.getLabel(), viewRange, leftYRange, monitor.getSpeedSeries(NetworkTrafficDataSeries.Type.BYTES_RECEIVED));
    RangedContinuousSeries sentSeries = new RangedContinuousSeries(NetworkTrafficDataSeries.Type.BYTES_SENT.getLabel(), viewRange, leftYRange, monitor.getSpeedSeries(NetworkTrafficDataSeries.Type.BYTES_SENT));
    RangedContinuousSeries connectionSeries = new RangedContinuousSeries("Connections", viewRange, rightYRange, monitor.getOpenConnectionsSeries());
    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();
    LineConfig receivedConfig = new LineConfig(ProfilerColors.NETWORK_RECEIVING_COLOR);
    lineChart.addLine(receivedSeries, receivedConfig);
    LineConfig sentConfig = new LineConfig(ProfilerColors.NETWORK_SENDING_COLOR);
    lineChart.addLine(sentSeries, sentConfig);
    LineConfig connectionConfig = new LineConfig(ProfilerColors.NETWORK_CONNECTIONS_COLOR).setStroke(LineConfig.DEFAULT_DASH_STROKE);
    lineChart.addLine(connectionSeries, connectionConfig);
    getChoreographer().register(lineChart);
    lineChartPanel.add(lineChart, BorderLayout.CENTER);
    final JPanel axisPanel = new JBPanel(new BorderLayout());
    axisPanel.setOpaque(false);
    AxisComponent.Builder leftAxisBuilder = new AxisComponent.Builder(leftYRange, TRAFFIC_AXIS_FORMATTER, 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 = leftAxisBuilder.build();
    getChoreographer().register(leftAxis);
    axisPanel.add(leftAxis, BorderLayout.WEST);
    AxisComponent.Builder rightAxisBuilder = new AxisComponent.Builder(rightYRange, CONNECTIONS_AXIS_FORMATTER, AxisComponent.AxisOrientation.LEFT).showAxisLine(false).showMax(true).showUnitAtMax(true).setMarkerLengths(MARKER_LENGTH, MARKER_LENGTH).clampToMajorTicks(true).setMargins(0, Y_AXIS_TOP_MARGIN);
    final AxisComponent rightAxis = rightAxisBuilder.build();
    getChoreographer().register(rightAxis);
    axisPanel.add(rightAxis, BorderLayout.EAST);
    final LegendComponent legend = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, LEGEND_UPDATE_FREQUENCY_MS);
    ArrayList<LegendRenderData> legendData = new ArrayList<>();
    legendData.add(lineChart.createLegendRenderData(receivedSeries, TRAFFIC_AXIS_FORMATTER, dataRange));
    legendData.add(lineChart.createLegendRenderData(sentSeries, TRAFFIC_AXIS_FORMATTER, dataRange));
    legendData.add(lineChart.createLegendRenderData(connectionSeries, CONNECTIONS_AXIS_FORMATTER, dataRange));
    legend.setLegendData(legendData);
    getChoreographer().register(legend);
    final JPanel legendPanel = new JBPanel(new BorderLayout());
    legendPanel.setOpaque(false);
    legendPanel.add(label, BorderLayout.WEST);
    legendPanel.add(legend, BorderLayout.EAST);
    SelectionComponent selection = new SelectionComponent(timeline.getSelectionRange(), timeline.getViewRange());
    selection.addChangeListener(this::onSelectionChanged);
    getChoreographer().register(selection);
    monitorPanel.add(selection, new TabularLayout.Constraint(0, 0));
    monitorPanel.add(legendPanel, new TabularLayout.Constraint(0, 0));
    monitorPanel.add(axisPanel, new TabularLayout.Constraint(0, 0));
    monitorPanel.add(lineChartPanel, new TabularLayout.Constraint(0, 0));
    // Give as much space as possible to the main monitor panel
    layout.setRowSizing(2, "*");
    panel.add(monitorPanel, new TabularLayout.Constraint(2, 0));
    return panel;
}
Also used : ArrayList(java.util.ArrayList) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) EventMonitorView(com.android.tools.profilers.event.EventMonitorView) EventMonitor(com.android.tools.profilers.event.EventMonitor) Range(com.android.tools.adtui.model.Range) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) JBPanel(com.intellij.ui.components.JBPanel) LineChart(com.android.tools.adtui.chart.linechart.LineChart) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with RangedContinuousSeries

use of com.android.tools.adtui.model.RangedContinuousSeries in project android by JetBrains.

the class LineChart method postAnimate.

@Override
public void postAnimate() {
    long duration = System.nanoTime();
    int p = 0;
    // Store the Y coordinates of the last stacked series to use them to increment the Y values
    // of the current stacked series.
    TDoubleArrayList lastStackedSeriesY = null;
    Deque<Path2D> orderedPaths = new ArrayDeque<>(myLinesConfig.size());
    Deque<LineConfig> orderedConfigs = new ArrayDeque<>(myLinesConfig.size());
    for (Map.Entry<RangedContinuousSeries, LineConfig> lineConfig : myLinesConfig.entrySet()) {
        final RangedContinuousSeries ranged = lineConfig.getKey();
        final LineConfig config = lineConfig.getValue();
        // Stores the y coordinates of the current series in case it's used as a stacked series
        final TDoubleArrayList currentSeriesY = new TDoubleArrayList();
        Path2D path = new Path2D.Float();
        double xMin = ranged.getXRange().getMin();
        double xMax = ranged.getXRange().getMax();
        double yMin = ranged.getYRange().getMin();
        double yMax = ranged.getYRange().getMax();
        // X coordinate of the first point
        double firstXd = 0f;
        List<SeriesData<Long>> seriesList = ranged.getSeries();
        for (int i = 0; i < seriesList.size(); i++) {
            // TODO: refactor to allow different types (e.g. double)
            SeriesData<Long> seriesData = seriesList.get(i);
            long currX = seriesData.x;
            long currY = seriesData.value;
            double xd = (currX - xMin) / (xMax - xMin);
            double yd = (currY - yMin) / (yMax - yMin);
            // prior iteration). In this case, yd of the current series shouldn't change.
            if (config.isStacked() && lastStackedSeriesY != null && i < lastStackedSeriesY.size()) {
                yd += lastStackedSeriesY.get(i);
            }
            currentSeriesY.add(yd);
            // Swing's (0, 0) coordinate is in top-left. As we use bottom-left (0, 0), we need to adjust the y coordinate.
            float adjustedYd = 1 - (float) yd;
            if (i == 0) {
                path.moveTo(xd, adjustedYd);
                firstXd = xd;
            } else {
                // drawing a line to the destination point itself (e.g. (x1, y1)).
                if (config.isStepped()) {
                    float y = (float) path.getCurrentPoint().getY();
                    path.lineTo(xd, y);
                }
                path.lineTo(xd, adjustedYd);
            }
        }
        if (config.isFilled() && path.getCurrentPoint() != null) {
            // If the chart is filled, but not stacked, draw a line from the last point to X
            // axis and another one from this new point to the first destination point.
            path.lineTo(path.getCurrentPoint().getX(), 1f);
            path.lineTo(firstXd, 1f);
        }
        if (config.isStacked()) {
            lastStackedSeriesY = currentSeriesY;
        }
        if (config.isFilled()) {
            // Draw the filled lines first, otherwise other lines won't be visible.
            // Also, to draw stacked and filled lines correctly, they need to be drawn in reverse order to their adding order.
            orderedPaths.addFirst(path);
            orderedConfigs.addFirst(config);
        } else {
            orderedPaths.addLast(path);
            orderedConfigs.addLast(config);
        }
        addDebugInfo("Range[%d] Max: %.2f", p, xMax);
        p++;
    }
    myLinePaths.clear();
    myLinePaths.addAll(orderedPaths);
    myLinePathConfigs.clear();
    myLinePathConfigs.addAll(orderedConfigs);
    addDebugInfo("postAnimate time: %d ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - duration));
}
Also used : Path2D(java.awt.geom.Path2D) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) SeriesData(com.android.tools.adtui.model.SeriesData) TDoubleArrayList(gnu.trove.TDoubleArrayList)

Example 10 with RangedContinuousSeries

use of com.android.tools.adtui.model.RangedContinuousSeries in project android by JetBrains.

the class AxisLineChartVisualTest method createComponentsList.

@Override
protected List<Animatable> createComponentsList() {
    mRangedData = new ArrayList<>();
    mData = new ArrayList<>();
    mLineChart = new LineChart();
    mStartTimeUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
    final Range timeCurrentRangeUs = new Range(0, 0);
    mTimeGlobalRangeUs = new Range(0, 0);
    mAnimatedTimeRange = new AnimatedTimeRange(mTimeGlobalRangeUs, mStartTimeUs);
    mScrollbar = new RangeScrollbar(mTimeGlobalRangeUs, timeCurrentRangeUs);
    // add horizontal time axis
    AxisComponent.Builder builder = new AxisComponent.Builder(timeCurrentRangeUs, TimeAxisFormatter.DEFAULT, AxisComponent.AxisOrientation.BOTTOM).setGlobalRange(mTimeGlobalRangeUs).setMargins(AXIS_SIZE, AXIS_SIZE);
    mTimeAxis = builder.build();
    // left memory data + axis
    Range yRange1Animatable = new Range(0, 100);
    builder = new AxisComponent.Builder(yRange1Animatable, MemoryAxisFormatter.DEFAULT, AxisComponent.AxisOrientation.LEFT).setLabel(SERIES1_LABEL).showMax(true).showUnitAtMax(true).setMargins(AXIS_SIZE, AXIS_SIZE);
    mMemoryAxis1 = builder.build();
    LongDataSeries series1 = new LongDataSeries();
    RangedContinuousSeries ranged1 = new RangedContinuousSeries(SERIES1_LABEL, timeCurrentRangeUs, yRange1Animatable, series1);
    mRangedData.add(ranged1);
    mData.add(series1);
    // right memory data + axis
    Range yRange2Animatable = new Range(0, 100);
    builder = new AxisComponent.Builder(yRange2Animatable, MemoryAxisFormatter.DEFAULT, AxisComponent.AxisOrientation.RIGHT).setLabel(SERIES2_LABEL).showMax(true).showUnitAtMax(true).setMargins(AXIS_SIZE, AXIS_SIZE);
    mMemoryAxis2 = builder.build();
    LongDataSeries series2 = new LongDataSeries();
    RangedContinuousSeries ranged2 = new RangedContinuousSeries(SERIES2_LABEL, timeCurrentRangeUs, yRange2Animatable, series2);
    mRangedData.add(ranged2);
    mData.add(series2);
    mLineChart.addLines(mRangedData);
    List<LegendRenderData> legendRenderInfo = new ArrayList<>();
    //Test the populated series case
    legendRenderInfo.add(mLineChart.createLegendRenderData(mRangedData.get(0), MemoryAxisFormatter.DEFAULT, mTimeGlobalRangeUs));
    //Test the null series case
    legendRenderInfo.add(new LegendRenderData(LegendRenderData.IconType.LINE, LineConfig.getColor(1), SERIES2_LABEL));
    mLegendComponent = new LegendComponent(LegendComponent.Orientation.VERTICAL, LABEL_UPDATE_MILLIS);
    mLegendComponent.setLegendData(legendRenderInfo);
    mGrid = new GridComponent();
    mGrid.addAxis(mTimeAxis);
    mGrid.addAxis(mMemoryAxis1);
    final AnimatedRange timeSelectionRangeUs = new AnimatedRange();
    mSelection = new SelectionComponent(timeSelectionRangeUs, timeCurrentRangeUs);
    // The comment on each line highlights why the component needs to be in that position.
    return // Update global time range immediate.
    Arrays.asList(// Update global time range immediate.
    mAnimatedTimeRange, // Update selection range immediate.
    mSelection, // Update current range immediate.
    mScrollbar, // Set y's interpolation values.
    mLineChart, // Clamp/interpolate ranges to major ticks if enabled.
    mMemoryAxis1, // Sync with mMemoryAxis1 if enabled.
    mMemoryAxis2, // Read ranges.
    mTimeAxis, // No-op.
    mGrid, timeSelectionRangeUs, // Reset flags.
    mLegendComponent);
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) ArrayList(java.util.ArrayList) Range(com.android.tools.adtui.model.Range) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Aggregations

RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)13 Range (com.android.tools.adtui.model.Range)12 LineChart (com.android.tools.adtui.chart.linechart.LineChart)7 LineConfig (com.android.tools.adtui.chart.linechart.LineConfig)6 JBPanel (com.intellij.ui.components.JBPanel)6 ArrayList (java.util.ArrayList)5 LongDataSeries (com.android.tools.adtui.model.LongDataSeries)4 SeriesData (com.android.tools.adtui.model.SeriesData)3 NotNull (org.jetbrains.annotations.NotNull)3 com.android.tools.adtui (com.android.tools.adtui)2 AxisComponent (com.android.tools.adtui.AxisComponent)2 LegendComponent (com.android.tools.adtui.LegendComponent)2 TabularLayout (com.android.tools.adtui.TabularLayout)2 SingleUnitAxisFormatter (com.android.tools.adtui.common.formatter.SingleUnitAxisFormatter)2 DefaultDataSeries (com.android.tools.adtui.model.DefaultDataSeries)2 EventMonitor (com.android.tools.profilers.event.EventMonitor)2 EventMonitorView (com.android.tools.profilers.event.EventMonitorView)2 java.awt (java.awt)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2