Search in sources :

Example 6 with LineChart

use of com.android.tools.adtui.chart.linechart.LineChart 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 7 with LineChart

use of com.android.tools.adtui.chart.linechart.LineChart 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)

Example 8 with LineChart

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

the class DataReducerVisualTest method createComponentsList.

@Override
protected List<Animatable> createComponentsList() {
    myGlobalXRange = new Range(0, 0);
    myViewXRange = new AnimatedRange();
    mySelectionXRange = new AnimatedRange();
    myYRange = new Range(0, 0);
    myLineChart = new LineChart((shape, config) -> shape);
    myOptimizedLineChart = new LineChart();
    myXAxis = new AxisComponent.Builder(myViewXRange, new SingleUnitAxisFormatter(1, 5, 1, ""), AxisComponent.AxisOrientation.BOTTOM).build();
    mySelection = new SelectionComponent(mySelectionXRange, myViewXRange);
    myData = new DefaultDataSeries<>();
    mySeries = new RangedContinuousSeries("Straight", myViewXRange, myYRange, myData);
    myLineChart.addLine(mySeries, new LineConfig(JBColor.BLUE));
    myOptimizedLineChart.addLine(mySeries, new LineConfig(JBColor.RED));
    return Arrays.asList(myViewXRange, mySelectionXRange, myLineChart, myOptimizedLineChart, myXAxis, mySelection);
}
Also used : ItemEvent(java.awt.event.ItemEvent) Range(com.android.tools.adtui.model.Range) Arrays(java.util.Arrays) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) DefaultDataSeries(com.android.tools.adtui.model.DefaultDataSeries) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LineChart(com.android.tools.adtui.chart.linechart.LineChart) ImmutableList(com.intellij.util.containers.ImmutableList) ComponentEvent(java.awt.event.ComponentEvent) AdtUiUtils(com.android.tools.adtui.common.AdtUiUtils) SingleUnitAxisFormatter(com.android.tools.adtui.common.formatter.SingleUnitAxisFormatter) java.awt(java.awt) ComponentAdapter(java.awt.event.ComponentAdapter) com.android.tools.adtui(com.android.tools.adtui) List(java.util.List) SeriesData(com.android.tools.adtui.model.SeriesData) JBLayeredPane(com.intellij.ui.components.JBLayeredPane) NotNull(org.jetbrains.annotations.NotNull) JBColor(com.intellij.ui.JBColor) javax.swing(javax.swing) SingleUnitAxisFormatter(com.android.tools.adtui.common.formatter.SingleUnitAxisFormatter) Range(com.android.tools.adtui.model.Range) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) LineChart(com.android.tools.adtui.chart.linechart.LineChart) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries)

Example 9 with LineChart

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

the class LineChartVisualTest method createComponentsList.

@Override
protected List<Animatable> createComponentsList() {
    mRangedData = new ArrayList<>();
    mData = new ArrayList<>();
    long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
    Range timeGlobalRangeUs = new Range(nowUs, nowUs + TimeUnit.SECONDS.toMicros(60));
    mLineChart = new LineChart();
    mAnimatedTimeRange = new AnimatedTimeRange(timeGlobalRangeUs, 0);
    List<Animatable> componentsList = new ArrayList<>();
    mySelectionComponent = new SelectionComponent(new Range(0, 0), timeGlobalRangeUs);
    myOverlayComponent = new OverlayComponent(mySelectionComponent);
    // Add the scene components to the list
    componentsList.add(mAnimatedTimeRange);
    componentsList.add(mLineChart);
    componentsList.add(mySelectionComponent);
    Range yRange = new Range(0.0, 100.0);
    for (int i = 0; i < 4; i++) {
        if (i % 2 == 0) {
            yRange = new Range(0.0, 100.0);
        }
        DefaultDataSeries<Long> series = new DefaultDataSeries<>();
        RangedContinuousSeries ranged = new RangedContinuousSeries("Widgets", timeGlobalRangeUs, yRange, series);
        mRangedData.add(ranged);
        mData.add(series);
    }
    mLineChart.addLines(mRangedData);
    mDurationData1 = new DefaultDataSeries<>();
    mDurationData2 = new DefaultDataSeries<>();
    RangedSeries<DefaultDurationData> series1 = new RangedSeries<>(timeGlobalRangeUs, mDurationData1);
    RangedSeries<DefaultDurationData> series2 = new RangedSeries<>(timeGlobalRangeUs, mDurationData2);
    mDurationRendererBlocking = new DurationDataRenderer.Builder(series1, Color.WHITE).setLabelColors(Color.DARK_GRAY, Color.GRAY, Color.lightGray, Color.WHITE).setIsBlocking(true).setIcon(UIManager.getIcon("Tree.leafIcon")).setLabelProvider(durationdata -> "Blocking").setClickHander(durationData -> mClickDisplayLabel.setText(durationData.toString())).build();
    mDurationRendererAttached = new DurationDataRenderer.Builder(series2, Color.WHITE).setLabelColors(Color.DARK_GRAY, Color.GRAY, Color.lightGray, Color.WHITE).setIcon(UIManager.getIcon("Tree.leafIcon")).setLabelProvider(durationdata -> "Attached").setAttachLineSeries(mRangedData.get(0)).setClickHander(durationData -> mClickDisplayLabel.setText(durationData.toString())).build();
    mLineChart.addCustomRenderer(mDurationRendererBlocking);
    mLineChart.addCustomRenderer(mDurationRendererAttached);
    myOverlayComponent.addDurationDataRenderer(mDurationRendererBlocking);
    myOverlayComponent.addDurationDataRenderer(mDurationRendererAttached);
    componentsList.add(mDurationRendererBlocking);
    componentsList.add(mDurationRendererAttached);
    componentsList.add(myOverlayComponent);
    return componentsList;
}
Also used : AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) ItemEvent(java.awt.event.ItemEvent) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) LineChart(com.android.tools.adtui.chart.linechart.LineChart) Animatable(com.android.tools.adtui.Animatable) AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) ImmutableList(com.intellij.util.containers.ImmutableList) SelectionComponent(com.android.tools.adtui.SelectionComponent) GBC_FULL(com.android.tools.adtui.common.AdtUiUtils.GBC_FULL) AdtUiUtils(com.android.tools.adtui.common.AdtUiUtils) MouseEvent(java.awt.event.MouseEvent) UNSPECIFIED_DURATION(com.android.tools.adtui.model.DurationData.UNSPECIFIED_DURATION) com.android.tools.adtui.model(com.android.tools.adtui.model) ArrayList(java.util.ArrayList) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) AnimatedComponent(com.android.tools.adtui.AnimatedComponent) DurationDataRenderer(com.android.tools.adtui.chart.linechart.DurationDataRenderer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MouseAdapter(java.awt.event.MouseAdapter) OverlayComponent(com.android.tools.adtui.chart.linechart.OverlayComponent) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) javax.swing(javax.swing) DurationDataRenderer(com.android.tools.adtui.chart.linechart.DurationDataRenderer) ArrayList(java.util.ArrayList) AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) SelectionComponent(com.android.tools.adtui.SelectionComponent) Animatable(com.android.tools.adtui.Animatable) OverlayComponent(com.android.tools.adtui.chart.linechart.OverlayComponent) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Example 10 with LineChart

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

the class MemoryProfilerStageView method buildMonitorUi.

@NotNull
private JPanel buildMonitorUi() {
    StudioProfilers profilers = getStage().getStudioProfilers();
    ProfilerTimeline timeline = profilers.getTimeline();
    Range viewRange = getTimeline().getViewRange();
    Range dataRange = getTimeline().getDataRange();
    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(3, 0));
    AxisComponent timeAxis = buildTimeAxis(profilers);
    getChoreographer().register(timeAxis);
    panel.add(timeAxis, new TabularLayout.Constraint(2, 0));
    EventMonitor events = new EventMonitor(profilers);
    EventMonitorView eventsView = new EventMonitorView(events);
    JComponent eventsComponent = eventsView.initialize(getChoreographer());
    panel.add(eventsComponent, new TabularLayout.Constraint(0, 0));
    MemoryMonitor monitor = new MemoryMonitor(profilers);
    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, 0);
    Range rightYRange = new Range(0, 0);
    RangedContinuousSeries javaSeries = new RangedContinuousSeries("Java", viewRange, leftYRange, monitor.getJavaMemory());
    RangedContinuousSeries nativeSeries = new RangedContinuousSeries("Native", viewRange, leftYRange, monitor.getNativeMemory());
    RangedContinuousSeries graphcisSeries = new RangedContinuousSeries("Graphics", viewRange, leftYRange, monitor.getGraphicsMemory());
    RangedContinuousSeries stackSeries = new RangedContinuousSeries("Stack", viewRange, leftYRange, monitor.getStackMemory());
    RangedContinuousSeries codeSeries = new RangedContinuousSeries("Code", viewRange, leftYRange, monitor.getCodeMemory());
    RangedContinuousSeries otherSeries = new RangedContinuousSeries("Others", viewRange, leftYRange, monitor.getOthersMemory());
    RangedContinuousSeries totalSeries = new RangedContinuousSeries("Total", viewRange, leftYRange, monitor.getTotalMemory());
    RangedContinuousSeries objectSeries = new RangedContinuousSeries("Allocated", viewRange, rightYRange, monitor.getObjectCount());
    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();
    lineChart.addLine(javaSeries, new LineConfig(ProfilerColors.MEMORY_JAVA).setFilled(true).setStacked(true));
    lineChart.addLine(nativeSeries, new LineConfig(ProfilerColors.MEMORY_NATIVE).setFilled(true).setStacked(true));
    lineChart.addLine(graphcisSeries, new LineConfig(ProfilerColors.MEMORY_GRAPHCIS).setFilled(true).setStacked(true));
    lineChart.addLine(stackSeries, new LineConfig(ProfilerColors.MEMORY_STACK).setFilled(true).setStacked(true));
    lineChart.addLine(codeSeries, new LineConfig(ProfilerColors.MEMORY_CODE).setFilled(true).setStacked(true));
    lineChart.addLine(otherSeries, new LineConfig(ProfilerColors.MEMORY_OTHERS).setFilled(true).setStacked(true));
    lineChart.addLine(totalSeries, new LineConfig(ProfilerColors.MEMORY_TOTAL).setFilled(true));
    lineChart.addLine(objectSeries, new LineConfig(ProfilerColors.MEMORY_OBJECTS).setStroke(LineConfig.DEFAULT_DASH_STROKE));
    // TODO set proper colors / icons
    DurationDataRenderer<HeapDumpDurationData> heapDumpRenderer = new DurationDataRenderer.Builder<>(new RangedSeries<>(viewRange, getStage().getHeapDumpSampleDurations()), Color.BLACK).setLabelColors(Color.DARK_GRAY, Color.GRAY, Color.lightGray, Color.WHITE).setStroke(new BasicStroke(2)).setIsBlocking(true).setLabelProvider(data -> String.format("Dump (%s)", data.getDuration() == DurationData.UNSPECIFIED_DURATION ? "in progress" : TimeAxisFormatter.DEFAULT.getFormattedString(viewRange.getLength(), data.getDuration(), true))).setClickHander(data -> getStage().setFocusedHeapDump(data.getDumpInfo())).build();
    DurationDataRenderer<AllocationsDurationData> allocationRenderer = new DurationDataRenderer.Builder<>(new RangedSeries<>(viewRange, getStage().getAllocationInfosDurations()), Color.LIGHT_GRAY).setLabelColors(Color.DARK_GRAY, Color.GRAY, Color.lightGray, Color.WHITE).setStroke(new BasicStroke(2)).setLabelProvider(data -> String.format("Allocation Record (%s)", data.getDuration() == DurationData.UNSPECIFIED_DURATION ? "in progress" : TimeAxisFormatter.DEFAULT.getFormattedString(viewRange.getLength(), data.getDuration(), true))).setClickHander(data -> getStage().setAllocationsTimeRange(data.getStartTimeNs(), data.getEndTimeNs())).build();
    DurationDataRenderer<GcDurationData> gcRenderer = new DurationDataRenderer.Builder<>(new RangedSeries<>(viewRange, monitor.getGcCount()), Color.BLACK).setIcon(myGcIcon).setAttachLineSeries(objectSeries).build();
    lineChart.addCustomRenderer(heapDumpRenderer);
    lineChart.addCustomRenderer(allocationRenderer);
    lineChart.addCustomRenderer(gcRenderer);
    SelectionComponent selection = new SelectionComponent(timeline.getSelectionRange(), timeline.getViewRange());
    final JPanel overlayPanel = new JBPanel(new BorderLayout());
    overlayPanel.setOpaque(false);
    overlayPanel.setBorder(BorderFactory.createEmptyBorder(Y_AXIS_TOP_MARGIN, 0, 0, 0));
    final OverlayComponent overlay = new OverlayComponent(selection);
    overlay.addDurationDataRenderer(heapDumpRenderer);
    overlay.addDurationDataRenderer(allocationRenderer);
    overlay.addDurationDataRenderer(gcRenderer);
    overlayPanel.add(overlay, BorderLayout.CENTER);
    getChoreographer().register(lineChart);
    getChoreographer().register(heapDumpRenderer);
    getChoreographer().register(allocationRenderer);
    getChoreographer().register(gcRenderer);
    getChoreographer().register(overlay);
    getChoreographer().register(selection);
    lineChartPanel.add(lineChart, BorderLayout.CENTER);
    final JPanel axisPanel = new JBPanel(new BorderLayout());
    axisPanel.setOpaque(false);
    AxisComponent.Builder leftBuilder = 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 = leftBuilder.build();
    getChoreographer().register(leftAxis);
    axisPanel.add(leftAxis, BorderLayout.WEST);
    AxisComponent.Builder rightBuilder = new AxisComponent.Builder(rightYRange, OBJECT_COUNT_AXIS_FORMATTER, AxisComponent.AxisOrientation.LEFT).showAxisLine(false).showMax(true).showUnitAtMax(true).clampToMajorTicks(true).setMarkerLengths(MARKER_LENGTH, MARKER_LENGTH).setMargins(0, Y_AXIS_TOP_MARGIN);
    final AxisComponent rightAxis = rightBuilder.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(javaSeries, MEMORY_AXIS_FORMATTER, dataRange));
    legendData.add(lineChart.createLegendRenderData(nativeSeries, MEMORY_AXIS_FORMATTER, dataRange));
    legendData.add(lineChart.createLegendRenderData(graphcisSeries, MEMORY_AXIS_FORMATTER, dataRange));
    legendData.add(lineChart.createLegendRenderData(stackSeries, MEMORY_AXIS_FORMATTER, dataRange));
    legendData.add(lineChart.createLegendRenderData(codeSeries, MEMORY_AXIS_FORMATTER, dataRange));
    legendData.add(lineChart.createLegendRenderData(otherSeries, MEMORY_AXIS_FORMATTER, dataRange));
    legendData.add(lineChart.createLegendRenderData(totalSeries, MEMORY_AXIS_FORMATTER, dataRange));
    legendData.add(lineChart.createLegendRenderData(objectSeries, OBJECT_COUNT_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);
    monitorPanel.add(overlayPanel, new TabularLayout.Constraint(0, 0));
    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 monitor as much space as possible
    layout.setRowSizing(1, "*");
    panel.add(monitorPanel, new TabularLayout.Constraint(1, 0));
    return panel;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) Range(com.android.tools.adtui.model.Range) AllIcons(com.intellij.icons.AllIcons) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LineChart(com.android.tools.adtui.chart.linechart.LineChart) RangedSeries(com.android.tools.adtui.model.RangedSeries) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ColoredTreeCellRenderer(com.intellij.ui.ColoredTreeCellRenderer) ArrayList(java.util.ArrayList) SingleUnitAxisFormatter(com.android.tools.adtui.common.formatter.SingleUnitAxisFormatter) EventMonitorView(com.android.tools.profilers.event.EventMonitorView) MemoryAxisFormatter(com.android.tools.adtui.common.formatter.MemoryAxisFormatter) OverlayComponent(com.android.tools.adtui.chart.linechart.OverlayComponent) BaseAxisFormatter(com.android.tools.adtui.common.formatter.BaseAxisFormatter) ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) Splitter(com.intellij.openapi.ui.Splitter) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) DurationData(com.android.tools.adtui.model.DurationData) ProfilerLayout(com.android.tools.profilers.ProfilerLayout) java.awt(java.awt) com.android.tools.adtui(com.android.tools.adtui) IconLoader(com.intellij.openapi.util.IconLoader) com.android.tools.profilers(com.android.tools.profilers) DurationDataRenderer(com.android.tools.adtui.chart.linechart.DurationDataRenderer) ClassObject(com.android.tools.profilers.memory.adapters.ClassObject) JBPanel(com.intellij.ui.components.JBPanel) EventMonitor(com.android.tools.profilers.event.EventMonitor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) CaptureObject(com.android.tools.profilers.memory.adapters.CaptureObject) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) TimeAxisFormatter(com.android.tools.adtui.common.formatter.TimeAxisFormatter) javax.swing(javax.swing) ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) DurationDataRenderer(com.android.tools.adtui.chart.linechart.DurationDataRenderer) 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) RangedSeries(com.android.tools.adtui.model.RangedSeries) JBPanel(com.intellij.ui.components.JBPanel) OverlayComponent(com.android.tools.adtui.chart.linechart.OverlayComponent) LineChart(com.android.tools.adtui.chart.linechart.LineChart) NotNull(org.jetbrains.annotations.NotNull)

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