Search in sources :

Example 1 with DefaultDataSeries

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

the class StateChartVisualTest method populateUi.

@Override
protected void populateUi(@NotNull JPanel panel) {
    panel.setLayout(new BorderLayout());
    JLayeredPane timelinePane = createMockTimeline();
    panel.add(timelinePane, BorderLayout.CENTER);
    final JPanel controls = new JPanel();
    LayoutManager manager = new BoxLayout(controls, BoxLayout.Y_AXIS);
    controls.setLayout(manager);
    panel.add(controls, BorderLayout.WEST);
    final AtomicInteger networkVariance = new AtomicInteger(MockFruitState.values().length);
    final AtomicInteger radioVariance = new AtomicInteger(MockStrengthState.values().length);
    final AtomicInteger delay = new AtomicInteger(100);
    //TODO Refactor this to come from the DataStore, in the mean time we will leak a thread every time reset is called on this test.
    Thread updateDataThread = new Thread() {

        @Override
        public void run() {
            super.run();
            try {
                // Store off the last state to simulate the same preprocessing the DataStore does on each series.
                TIntArrayList lastNetworkData = new TIntArrayList();
                TIntArrayList lastRadioVariance = new TIntArrayList();
                while (true) {
                    long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
                    int v = networkVariance.get();
                    for (int i = 0; i < mNetworkDataEntries.size(); i++) {
                        DefaultDataSeries<MockFruitState> series = mNetworkDataEntries.get(i);
                        if (Math.random() > 0.5f) {
                            int index = (int) (Math.random() * v);
                            if (lastNetworkData.size() <= i) {
                                lastNetworkData.add(-1);
                            }
                            if (lastNetworkData.get(i) != index) {
                                series.add(nowUs, MockFruitState.values()[index]);
                                lastNetworkData.set(i, index);
                            }
                        }
                    }
                    v = radioVariance.get();
                    for (int i = 0; i < mRadioDataEntries.size(); i++) {
                        DefaultDataSeries<MockStrengthState> series = mRadioDataEntries.get(i);
                        if (Math.random() > 0.5f) {
                            int index = (int) (Math.random() * v);
                            if (lastRadioVariance.size() <= i) {
                                lastRadioVariance.add(-1);
                            }
                            if (lastRadioVariance.get(i) != index) {
                                series.add(nowUs, MockStrengthState.values()[index]);
                                lastRadioVariance.set(i, index);
                            }
                        }
                    }
                    Thread.sleep(delay.get());
                }
            } catch (InterruptedException e) {
            }
        }
    };
    updateDataThread.start();
    controls.add(VisualTest.createVariableSlider("ArcWidth", 0, 100, new VisualTests.Value() {

        @Override
        public void set(int v) {
            mNetworkStatusChart.setArcWidth(v / 100f);
            mRadioStateChart.setArcWidth(v / 100f);
        }

        @Override
        public int get() {
            // unused
            return -1;
        }
    }));
    controls.add(VisualTest.createVariableSlider("ArcHeight", 0, 100, new VisualTests.Value() {

        @Override
        public void set(int v) {
            mNetworkStatusChart.setArcHeight(v / 100f);
            mRadioStateChart.setArcHeight(v / 100f);
        }

        @Override
        public int get() {
            // unused
            return -1;
        }
    }));
    controls.add(VisualTest.createVariableSlider("Gap", 0, 100, new VisualTests.Value() {

        @Override
        public void set(int v) {
            mNetworkStatusChart.setHeightGap(v / 100f);
            mRadioStateChart.setHeightGap(v / 100f);
        }

        @Override
        public int get() {
            // unused
            return -1;
        }
    }));
    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("Fruit Variance", 1, MockFruitState.values().length, new VisualTests.Value() {

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

        @Override
        public int get() {
            return networkVariance.get();
        }
    }));
    controls.add(VisualTest.createVariableSlider("Strength Variance", 1, MockStrengthState.values().length, new VisualTests.Value() {

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

        @Override
        public int get() {
            return radioVariance.get();
        }
    }));
    controls.add(VisualTest.createButton("Add Fruit Series", e -> {
        DefaultDataSeries<MockFruitState> networkSeries = new DefaultDataSeries<>();
        RangedSeries<MockFruitState> networkData = new RangedSeries(mTimeGlobalRangeUs, networkSeries);
        mNetworkStatusChart.addSeries(networkData);
        mNetworkDataEntries.add(networkSeries);
    }));
    controls.add(VisualTest.createButton("Add Strength Series", e -> {
        DefaultDataSeries<MockStrengthState> radioSeries = new DefaultDataSeries<>();
        RangedSeries<MockStrengthState> radioData = new RangedSeries(mTimeGlobalRangeUs, radioSeries);
        mRadioStateChart.addSeries(radioData);
        mRadioDataEntries.add(radioSeries);
    }));
    controls.add(VisualTest.createCheckbox("Shift xRange Min", itemEvent -> mAnimatedTimeRange.setShift(itemEvent.getStateChange() == ItemEvent.SELECTED)));
    controls.add(VisualTest.createCheckbox("Text Mode", itemEvent -> {
        StateChart.RenderMode mode = itemEvent.getStateChange() == ItemEvent.SELECTED ? StateChart.RenderMode.TEXT : StateChart.RenderMode.BAR;
        mNetworkStatusChart.setRenderMode(mode);
        mRadioStateChart.setRenderMode(mode);
    }));
    controls.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
}
Also used : ItemEvent(java.awt.event.ItemEvent) Range(com.android.tools.adtui.model.Range) Arrays(java.util.Arrays) AxisComponent(com.android.tools.adtui.AxisComponent) DefaultDataSeries(com.android.tools.adtui.model.DefaultDataSeries) StateChart(com.android.tools.adtui.chart.StateChart) EnumMap(java.util.EnumMap) RangedSeries(com.android.tools.adtui.model.RangedSeries) Animatable(com.android.tools.adtui.Animatable) AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) ComponentEvent(java.awt.event.ComponentEvent) ArrayList(java.util.ArrayList) java.awt(java.awt) ComponentAdapter(java.awt.event.ComponentAdapter) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) AnimatedComponent(com.android.tools.adtui.AnimatedComponent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NotNull(org.jetbrains.annotations.NotNull) TIntArrayList(gnu.trove.TIntArrayList) JBColor(com.intellij.ui.JBColor) javax.swing(javax.swing) RangedSeries(com.android.tools.adtui.model.RangedSeries) TIntArrayList(gnu.trove.TIntArrayList) DefaultDataSeries(com.android.tools.adtui.model.DefaultDataSeries) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with DefaultDataSeries

use of com.android.tools.adtui.model.DefaultDataSeries 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 3 with DefaultDataSeries

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

the class NetworkCaptureSegment method animate.

@Override
public void animate(float frameLength) {
    myDataList = myModel.getData(myTimeCurrentRangeUs);
    // TODO: currently we recreate charts from scratch, instead consider reusing charts
    myCharts.clear();
    for (HttpData data : myDataList) {
        DefaultDataSeries<NetworkState> series = new DefaultDataSeries<>();
        series.add(0, NetworkState.NONE);
        series.add(data.getStartTimeUs(), NetworkState.SENDING);
        if (data.getDownloadingTimeUs() > 0) {
            series.add(data.getDownloadingTimeUs(), NetworkState.RECEIVING);
        }
        if (data.getEndTimeUs() > 0) {
            series.add(data.getEndTimeUs(), NetworkState.NONE);
        }
        StateChart<NetworkState> chart = new StateChart<>(NETWORK_STATE_COLORS);
        chart.addSeries(new RangedSeries<>(myTimeCurrentRangeUs, series));
        chart.animate(frameLength);
        myCharts.add(chart);
    }
}
Also used : DefaultDataSeries(com.android.tools.adtui.model.DefaultDataSeries) HttpData(com.android.tools.idea.monitor.ui.network.model.HttpData) StateChart(com.android.tools.adtui.chart.StateChart)

Example 4 with DefaultDataSeries

use of com.android.tools.adtui.model.DefaultDataSeries 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 5 with DefaultDataSeries

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

the class StateChartReducerVisualTest method createComponentsList.

@Override
protected List<Animatable> createComponentsList() {
    myViewRange = new Range();
    myData = new DefaultDataSeries<>();
    RangedSeries<ColorState> series = new RangedSeries<>(myViewRange, myData);
    myColorChart = new StateChart<>(COLOR_STATE_COLORS, (rectangles, values) -> {
    });
    myColorChart.addSeries(series);
    myOptimizedColorChart = new StateChart<>(COLOR_STATE_COLORS);
    myOptimizedColorChart.addSeries(series);
    return Arrays.asList(myColorChart, myOptimizedColorChart);
}
Also used : ItemEvent(java.awt.event.ItemEvent) Range(com.android.tools.adtui.model.Range) Arrays(java.util.Arrays) DefaultDataSeries(com.android.tools.adtui.model.DefaultDataSeries) StateChart(com.android.tools.adtui.chart.StateChart) EnumMap(java.util.EnumMap) RangedSeries(com.android.tools.adtui.model.RangedSeries) Random(java.util.Random) AdtUiUtils(com.android.tools.adtui.common.AdtUiUtils) java.awt(java.awt) com.android.tools.adtui(com.android.tools.adtui) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull) JBColor(com.intellij.ui.JBColor) javax.swing(javax.swing) Range(com.android.tools.adtui.model.Range) RangedSeries(com.android.tools.adtui.model.RangedSeries)

Aggregations

DefaultDataSeries (com.android.tools.adtui.model.DefaultDataSeries)6 Range (com.android.tools.adtui.model.Range)5 StateChart (com.android.tools.adtui.chart.StateChart)3 RangedSeries (com.android.tools.adtui.model.RangedSeries)3 JBColor (com.intellij.ui.JBColor)3 java.awt (java.awt)3 ItemEvent (java.awt.event.ItemEvent)3 Arrays (java.util.Arrays)3 List (java.util.List)3 javax.swing (javax.swing)3 NotNull (org.jetbrains.annotations.NotNull)3 com.android.tools.adtui (com.android.tools.adtui)2 AnimatedTimeRange (com.android.tools.adtui.AnimatedTimeRange)2 AdtUiUtils (com.android.tools.adtui.common.AdtUiUtils)2 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)2 ComponentAdapter (java.awt.event.ComponentAdapter)2 ComponentEvent (java.awt.event.ComponentEvent)2 EnumMap (java.util.EnumMap)2 Animatable (com.android.tools.adtui.Animatable)1 AnimatedComponent (com.android.tools.adtui.AnimatedComponent)1