Search in sources :

Example 1 with SeriesData

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

the class LineChart method updateData.

@Override
protected void updateData() {
    Map<Range, Double> max = new HashMap<>();
    // TODO Handle stacked configs
    for (RangedContinuousSeries ranged : myLinesConfig.keySet()) {
        Range range = ranged.getYRange();
        double yMax = Double.MIN_VALUE;
        ImmutableList<SeriesData<Long>> seriesList = ranged.getSeries();
        for (int i = 0; i < seriesList.size(); i++) {
            double value = seriesList.get(i).value;
            if (yMax < value) {
                yMax = value;
            }
        }
        Double m = max.get(range);
        max.put(range, m == null ? yMax : Math.max(yMax, m));
    }
    for (Map.Entry<Range, Double> entry : max.entrySet()) {
        Range range = entry.getKey();
        // Prevent the LineChart to update the range below its current max.
        if (range.getMax() < entry.getValue()) {
            float fraction = myFirstUpdate ? 1f : DEFAULT_LERP_FRACTION;
            range.setMax(Choreographer.lerp(range.getMax(), entry.getValue(), fraction, mFrameLength, (float) (entry.getValue() * DEFAULT_LERP_THRESHOLD_PERCENTAGE)));
        }
    }
    myFirstUpdate = false;
}
Also used : SeriesData(com.android.tools.adtui.model.SeriesData) Range(com.android.tools.adtui.model.Range) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries)

Example 2 with SeriesData

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

the class AccordionVisualTest method populateUi.

@Override
protected void populateUi(@NotNull JPanel panel) {
    panel.setLayout(new GridLayout(0, 1));
    Thread mUpdateDataThread = new Thread() {

        @Override
        public void run() {
            try {
                while (true) {
                    long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime()) - mStartTimeUs;
                    for (LongDataSeries series : mData) {
                        ImmutableList<SeriesData<Long>> data = series.getAllData();
                        long last = data.isEmpty() ? 0 : data.get(data.size() - 1).value;
                        float delta = 10 * ((float) Math.random() - 0.45f);
                        series.add(nowUs, last + (long) delta);
                    }
                    Thread.sleep(LINECHART_DATA_DELAY);
                }
            } catch (InterruptedException e) {
            }
        }
    };
    mUpdateDataThread.start();
    // Creates the vertical accordion at the top half.
    JBPanel yPanel = new JBPanel();
    panel.add(yPanel);
    yPanel.setBorder(BorderFactory.createLineBorder(AdtUiUtils.DEFAULT_BORDER_COLOR));
    final JPanel controlsY = VisualTest.createControlledPane(yPanel, mPanelY);
    controlsY.add(VisualTest.createButton("Reset Weights", listener -> {
        mAccordionY.resetComponents();
    }));
    controlsY.add(VisualTest.createButton("Add Chart", listener -> {
        final LineChart chart = generateChart(mAccordionY, AccordionLayout.Orientation.VERTICAL, 0, PREFERRED_SIZE, Integer.MAX_VALUE);
        mPanelY.add(chart);
        mChartCountY++;
    }));
    controlsY.add(VisualTest.createButton("Add Chart With Min", listener -> {
        final LineChart chart = generateChart(mAccordionY, AccordionLayout.Orientation.VERTICAL, MIN_SIZE, PREFERRED_SIZE, Integer.MAX_VALUE);
        mPanelY.add(chart);
        mChartCountY++;
    }));
    controlsY.add(VisualTest.createButton("Add Chart With Small Max", listener -> {
        final LineChart chart = generateChart(mAccordionY, AccordionLayout.Orientation.VERTICAL, 0, PREFERRED_SIZE, MAX_SIZE);
        mPanelY.add(chart);
        mChartCountY++;
    }));
    controlsY.add(VisualTest.createButton("Remove Last Chart", listener -> {
        mPanelY.remove(--mChartCountY);
    }));
    controlsY.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
    // Creates the horizontal accordion at the bottom half.
    JBPanel xPanel = new JBPanel();
    panel.add(xPanel);
    xPanel.setBorder(BorderFactory.createLineBorder(AdtUiUtils.DEFAULT_BORDER_COLOR));
    final JPanel controlsX = VisualTest.createControlledPane(xPanel, mPanelX);
    controlsX.add(VisualTest.createButton("Reset Weights", listener -> {
        mAccordionX.resetComponents();
    }));
    controlsX.add(VisualTest.createButton("Add Chart", listener -> {
        final LineChart chart = generateChart(mAccordionX, AccordionLayout.Orientation.HORIZONTAL, 0, PREFERRED_SIZE, Integer.MAX_VALUE);
        mPanelX.add(chart);
        mChartCountX++;
    }));
    controlsX.add(VisualTest.createButton("Add Chart With Min", listener -> {
        final LineChart chart = generateChart(mAccordionX, AccordionLayout.Orientation.HORIZONTAL, MIN_SIZE, PREFERRED_SIZE, Integer.MAX_VALUE);
        mPanelX.add(chart);
        mChartCountX++;
    }));
    controlsX.add(VisualTest.createButton("Add Chart With Small Max", listener -> {
        final LineChart chart = generateChart(mAccordionX, AccordionLayout.Orientation.HORIZONTAL, 0, PREFERRED_SIZE, MAX_SIZE);
        mPanelX.add(chart);
        mChartCountX++;
    }));
    controlsX.add(VisualTest.createButton("Remove Last Chart", listener -> {
        mPanelX.remove(--mChartCountX);
    }));
    controlsX.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) Range(com.android.tools.adtui.model.Range) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LineChart(com.android.tools.adtui.chart.linechart.LineChart) ImmutableList(com.intellij.util.containers.ImmutableList) AdtUiUtils(com.android.tools.adtui.common.AdtUiUtils) MouseEvent(java.awt.event.MouseEvent) ArrayList(java.util.ArrayList) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) com.android.tools.adtui(com.android.tools.adtui) List(java.util.List) SeriesData(com.android.tools.adtui.model.SeriesData) JBPanel(com.intellij.ui.components.JBPanel) MouseAdapter(java.awt.event.MouseAdapter) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) LongDataSeries(com.android.tools.adtui.model.LongDataSeries) JBPanel(com.intellij.ui.components.JBPanel) SeriesData(com.android.tools.adtui.model.SeriesData) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Example 3 with SeriesData

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

the class AxisLineChartVisualTest method populateUi.

@Override
protected void populateUi(@NotNull JPanel panel) {
    panel.setLayout(new BorderLayout());
    JLayeredPane mockTimelinePane = createMockTimeline();
    panel.add(mockTimelinePane, BorderLayout.CENTER);
    final JBPanel controls = new JBPanel();
    LayoutManager manager = new BoxLayout(controls, BoxLayout.Y_AXIS);
    controls.setLayout(manager);
    panel.add(controls, BorderLayout.WEST);
    final AtomicInteger variance = new AtomicInteger(10);
    final AtomicInteger delay = new AtomicInteger(10);
    Thread mUpdateDataThread = new Thread() {

        @Override
        public void run() {
            try {
                while (true) {
                    long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime()) - mStartTimeUs;
                    for (LongDataSeries series : mData) {
                        ImmutableList<SeriesData<Long>> data = series.getAllData();
                        long last = data.isEmpty() ? 0 : data.get(data.size() - 1).value;
                        float delta = 10 * ((float) Math.random() - 0.45f);
                        series.add(nowUs, last + (long) delta);
                    }
                    Thread.sleep(delay.get());
                }
            } catch (InterruptedException e) {
            }
        }
    };
    mUpdateDataThread.start();
    controls.add(VisualTest.createVariableSlider("Delay", 10, 5000, new VisualTests.Value() {

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

        @Override
        public int get() {
            return delay.get();
        }
    }));
    controls.add(VisualTest.createVariableSlider("Variance", 0, 50, new VisualTests.Value() {

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

        @Override
        public int get() {
            return variance.get();
        }
    }));
    controls.add(VisualTest.createCheckbox("Stable Scroll", itemEvent -> mScrollbar.setStableScrolling(itemEvent.getStateChange() == ItemEvent.SELECTED)));
    controls.add(VisualTest.createCheckbox("Clamp To Major Ticks", itemEvent -> mMemoryAxis1.setClampToMajorTicks(itemEvent.getStateChange() == ItemEvent.SELECTED)));
    controls.add(VisualTest.createCheckbox("Sync Vertical Axes", itemEvent -> mMemoryAxis2.setParentAxis(itemEvent.getStateChange() == ItemEvent.SELECTED ? mMemoryAxis1 : null)));
    controls.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) ItemEvent(java.awt.event.ItemEvent) Range(com.android.tools.adtui.model.Range) Arrays(java.util.Arrays) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) 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) ArrayList(java.util.ArrayList) java.awt(java.awt) ComponentAdapter(java.awt.event.ComponentAdapter) TimeUnit(java.util.concurrent.TimeUnit) com.android.tools.adtui(com.android.tools.adtui) List(java.util.List) MemoryAxisFormatter(com.android.tools.adtui.common.formatter.MemoryAxisFormatter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SeriesData(com.android.tools.adtui.model.SeriesData) JBLayeredPane(com.intellij.ui.components.JBLayeredPane) JBPanel(com.intellij.ui.components.JBPanel) NotNull(org.jetbrains.annotations.NotNull) TimeAxisFormatter(com.android.tools.adtui.common.formatter.TimeAxisFormatter) javax.swing(javax.swing) LongDataSeries(com.android.tools.adtui.model.LongDataSeries) JBPanel(com.intellij.ui.components.JBPanel) SeriesData(com.android.tools.adtui.model.SeriesData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 4 with SeriesData

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

the class CpuMonitorTest method testOtherProcessesCpuUsage.

@Test
public void testOtherProcessesCpuUsage() throws IOException {
    CpuUsageDataSeries series = myMonitor.getOtherProcessesCpuUsage();
    ImmutableList<SeriesData<Long>> seriesDataList = series.getDataForXRange(new Range());
    // Only other processes information.
    assertEquals(1, seriesDataList.size());
    SeriesData<Long> seriesData = seriesDataList.get(0);
    assertNotNull(seriesData);
    assertEquals(40, (long) seriesData.value);
}
Also used : SeriesData(com.android.tools.adtui.model.SeriesData) Range(com.android.tools.adtui.model.Range) Test(org.junit.Test)

Example 5 with SeriesData

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

the class CpuMonitorTest method testThisProcessCpuUsage.

@Test
public void testThisProcessCpuUsage() throws IOException {
    CpuUsageDataSeries series = myMonitor.getThisProcessCpuUsage();
    ImmutableList<SeriesData<Long>> seriesDataList = series.getDataForXRange(new Range());
    // Only current process information.
    assertEquals(1, seriesDataList.size());
    SeriesData<Long> seriesData = seriesDataList.get(0);
    assertNotNull(seriesData);
    assertEquals(20, (long) seriesData.value);
}
Also used : SeriesData(com.android.tools.adtui.model.SeriesData) Range(com.android.tools.adtui.model.Range) Test(org.junit.Test)

Aggregations

SeriesData (com.android.tools.adtui.model.SeriesData)9 Range (com.android.tools.adtui.model.Range)7 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 com.android.tools.adtui (com.android.tools.adtui)2 LineChart (com.android.tools.adtui.chart.linechart.LineChart)2 LongDataSeries (com.android.tools.adtui.model.LongDataSeries)2 JBPanel (com.intellij.ui.components.JBPanel)2 ImmutableList (com.intellij.util.containers.ImmutableList)2 java.awt (java.awt)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 javax.swing (javax.swing)2 NotNull (org.jetbrains.annotations.NotNull)2 LineConfig (com.android.tools.adtui.chart.linechart.LineConfig)1 AdtUiUtils (com.android.tools.adtui.common.AdtUiUtils)1 MemoryAxisFormatter (com.android.tools.adtui.common.formatter.MemoryAxisFormatter)1 TimeAxisFormatter (com.android.tools.adtui.common.formatter.TimeAxisFormatter)1 MemoryProfiler (com.android.tools.profiler.proto.MemoryProfiler)1