Search in sources :

Example 16 with Range

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

the class AccordionVisualTest method createComponentsList.

@Override
protected List<Animatable> createComponentsList() {
    mStartTimeUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
    Range timeGlobalRangeUs = new Range(0, 0);
    mAnimatedTimeRange = new AnimatedTimeRange(timeGlobalRangeUs, mStartTimeUs);
    mPanelX = new JBPanel();
    mPanelY = new JBPanel();
    mAccordionX = new AccordionLayout(mPanelX, AccordionLayout.Orientation.HORIZONTAL);
    mAccordionY = new AccordionLayout(mPanelY, AccordionLayout.Orientation.VERTICAL);
    mPanelX.setLayout(mAccordionX);
    mPanelY.setLayout(mAccordionY);
    List<Animatable> componentsList = new ArrayList<>();
    // Add the scene components to the list
    componentsList.add(mAccordionX);
    componentsList.add(mAccordionY);
    componentsList.add(mAnimatedTimeRange);
    mRangedData = new ArrayList<>();
    mData = new ArrayList<>();
    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);
        }
        LongDataSeries series = new LongDataSeries();
        RangedContinuousSeries ranged = new RangedContinuousSeries("Widgets", timeGlobalRangeUs, yRange, series);
        mRangedData.add(ranged);
        mData.add(series);
    }
    return componentsList;
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) ArrayList(java.util.ArrayList) Range(com.android.tools.adtui.model.Range) JBPanel(com.intellij.ui.components.JBPanel) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries)

Example 17 with Range

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

the class FlameGraphVisualTest method actionPerformed.

/**
   * Invoked when an action occurs.
   */
@Override
public void actionPerformed(ActionEvent e) {
    if (ACTION_START_RECORDING.equals(e.getActionCommand())) {
        if (mSampler == null) {
            mSampler = new Sampler();
        }
        mSampler.startSampling();
        mRecordButton.setActionCommand(ACTION_STOP_RECORDING);
        mRecordButton.setText("Stop Recording");
    } else if (ACTION_STOP_RECORDING.equals(e.getActionCommand())) {
        mSampler.stopSampling();
        mRecordButton.setActionCommand(ACTION_START_RECORDING);
        mRecordButton.setText("Record");
        setData(mSampler.getData());
    } else if (ACTION_SAVE_RECORDING.equals(e.getActionCommand())) {
    } else if (ACTION_LOAD_RECORDING.equals(e.getActionCommand())) {
    } else if (ACTION_THREAD_SELECTED.equals(e.getActionCommand())) {
        int selected = mComboBox.getSelectedIndex();
        if (selected >= 0 && selected < mComboBox.getItemCount()) {
            String threadName = (String) mComboBox.getSelectedItem();
            mtree = furnace.get(threadName);
            mChart.setHTree(mtree);
            double start = mtree.getFirstChild().getStart();
            double end = mtree.getLastChild().getEnd();
            mTimeGlobalRangeUs.setMin(start);
            mTimeGlobalRangeUs.setMax(end);
            mTimeSelectionRangeUs.setMin(start);
            mTimeSelectionRangeUs.setMax(end);
            // Generate dummy values to simulate CPU Load.
            LongDataSeries series = new LongDataSeries();
            RangedContinuousSeries rangedSeries = new RangedContinuousSeries("CPU Load", mTimeGlobalRangeUs, new Range(0.0, (float) Sampler.MAX_VALUE), series);
            Random r = new Random(System.currentTimeMillis());
            for (int i = 0; i < 100; i++) {
                series.add((long) (start + (end - start) / 100 * i), (long) r.nextInt(100));
            }
            mLineChart.addLine(rangedSeries);
            mScrollBar.setValues(mChart.getMaximumHeight() - mChart.getHeight(), mChart.getHeight(), 0, mChart.getMaximumHeight());
        }
    }
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) Range(com.android.tools.adtui.model.Range) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries)

Example 18 with Range

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

the class LineChartTest method testSnapToDataMaxOnFirstUpdate.

@Test
public void testSnapToDataMaxOnFirstUpdate() throws Exception {
    // Test that during the first update, the LineChart will immediately snap to the current data max instead of interpolating.
    Range xRange = new Range(0, 100);
    Range yRange = new Range(0, 50);
    DefaultDataSeries<Long> testSeries = new DefaultDataSeries<>();
    for (int i = 0; i < 101; i++) {
        testSeries.add(i, (long) i);
    }
    RangedContinuousSeries rangedSeries = new RangedContinuousSeries("test", xRange, yRange, testSeries);
    Choreographer choreographer = new Choreographer(new JPanel());
    choreographer.setUpdate(false);
    LineChart lineChart = new LineChart();
    lineChart.addLine(rangedSeries);
    choreographer.register(lineChart);
    // before update.
    assertThat(yRange.getMax()).isWithin(0.0).of(50);
    choreographer.step();
    // after update.
    assertThat(yRange.getMax()).isWithin(0.0).of(100);
    choreographer.stop();
}
Also used : Choreographer(com.android.tools.adtui.Choreographer) DefaultDataSeries(com.android.tools.adtui.model.DefaultDataSeries) Range(com.android.tools.adtui.model.Range) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) Test(org.junit.Test)

Example 19 with Range

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

the class AxisComponentTest method testBuilder.

@Test
public void testBuilder() throws Exception {
    // A simple test to validate that the AxisComponent generated from the Builder has consistent values as the input.
    AnimatedRange testRange1 = new AnimatedRange(0, 100);
    TimeAxisFormatter testFormatter1 = new TimeAxisFormatter(5, 5, 10);
    AxisComponent.Builder builder = new AxisComponent.Builder(testRange1, testFormatter1, AxisComponent.AxisOrientation.BOTTOM);
    AxisComponent axis1 = builder.build();
    assertThat(axis1.getRange()).isEqualTo(testRange1);
    assertThat(axis1.getLabel()).isNull();
    assertThat(axis1.getAxisFormatter()).isEqualTo(testFormatter1);
    assertThat(axis1.getOrientation()).isEqualTo(AxisComponent.AxisOrientation.BOTTOM);
    assertThat(axis1.getGlobalRange()).isNull();
    assertThat(axis1.getParentAxis()).isNull();
    assertThat(axis1.getClampToMajorTicks()).isFalse();
    assertThat(axis1.getShowMin()).isFalse();
    assertThat(axis1.getShowMax()).isFalse();
    assertThat(axis1.getShowAxisLine()).isTrue();
    Range testRange2 = new Range(0, 200);
    builder = new AxisComponent.Builder(testRange1, testFormatter1, AxisComponent.AxisOrientation.TOP).setParentAxis(axis1).setGlobalRange(testRange2).setLabel("Axis").showMax(true).showAxisLine(false).clampToMajorTicks(true);
    AxisComponent axis2 = builder.build();
    assertThat(axis2.getRange()).isEqualTo(testRange1);
    assertThat(axis2.getLabel()).isEqualTo("Axis");
    assertThat(axis2.getAxisFormatter()).isEqualTo(testFormatter1);
    assertThat(axis2.getOrientation()).isEqualTo(AxisComponent.AxisOrientation.TOP);
    assertThat(axis2.getGlobalRange()).isEqualTo(testRange2);
    assertThat(axis2.getParentAxis()).isEqualTo(axis1);
    assertThat(axis2.getClampToMajorTicks()).isTrue();
    assertThat(axis2.getShowMin()).isFalse();
    assertThat(axis2.getShowMax()).isTrue();
    assertThat(axis2.getShowAxisLine()).isFalse();
}
Also used : TimeAxisFormatter(com.android.tools.adtui.common.formatter.TimeAxisFormatter) Range(com.android.tools.adtui.model.Range) Test(org.junit.Test)

Example 20 with Range

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

the class AxisComponentTest method testClampToMajorTickOnFirstUpdate.

@Test
public void testClampToMajorTickOnFirstUpdate() throws Exception {
    // Test that during the first update, if the AxisComponent is set to clamp to the next major tick,
    // The range will be immediately snapped to the major tick value instead of going through interpolation.
    // Subsequent updates will interpolate to the major tick.
    // Setting the minimum tick value to 10, so that a Range of {0,5} should adjust to {0,10} by the axis.
    SingleUnitAxisFormatter formatter = new SingleUnitAxisFormatter(1, 1, 10, "");
    Range range = new Range(0, 5);
    Choreographer choreographer = new Choreographer(new JPanel());
    choreographer.setUpdate(false);
    AxisComponent.Builder builder = new AxisComponent.Builder(range, formatter, AxisComponent.AxisOrientation.LEFT).clampToMajorTicks(true);
    AxisComponent axis = builder.build();
    choreographer.register(axis);
    // before update.
    assertThat(axis.getRange().getMax()).isWithin(0.0).of(5);
    choreographer.step();
    // after update.
    assertThat(axis.getRange().getMax()).isWithin(0.0).of(10);
    choreographer.stop();
}
Also used : SingleUnitAxisFormatter(com.android.tools.adtui.common.formatter.SingleUnitAxisFormatter) Range(com.android.tools.adtui.model.Range) Test(org.junit.Test)

Aggregations

Range (com.android.tools.adtui.model.Range)38 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 JBPanel (com.intellij.ui.components.JBPanel)9 LineChart (com.android.tools.adtui.chart.linechart.LineChart)7 SeriesData (com.android.tools.adtui.model.SeriesData)7 LineConfig (com.android.tools.adtui.chart.linechart.LineConfig)6 NotNull (org.jetbrains.annotations.NotNull)6 java.awt (java.awt)5 javax.swing (javax.swing)5 Animatable (com.android.tools.adtui.Animatable)4 AnimatedTimeRange (com.android.tools.adtui.AnimatedTimeRange)4 DefaultDataSeries (com.android.tools.adtui.model.DefaultDataSeries)4 LongDataSeries (com.android.tools.adtui.model.LongDataSeries)4 List (java.util.List)4 com.android.tools.adtui (com.android.tools.adtui)3 SingleUnitAxisFormatter (com.android.tools.adtui.common.formatter.SingleUnitAxisFormatter)3 RangedSeries (com.android.tools.adtui.model.RangedSeries)3 ProfilerEventListener (com.android.tools.idea.monitor.tool.ProfilerEventListener)3