Search in sources :

Example 1 with SingleUnitAxisFormatter

use of com.android.tools.adtui.common.formatter.SingleUnitAxisFormatter 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)

Example 2 with SingleUnitAxisFormatter

use of com.android.tools.adtui.common.formatter.SingleUnitAxisFormatter 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)

Aggregations

SingleUnitAxisFormatter (com.android.tools.adtui.common.formatter.SingleUnitAxisFormatter)2 Range (com.android.tools.adtui.model.Range)2 com.android.tools.adtui (com.android.tools.adtui)1 LineChart (com.android.tools.adtui.chart.linechart.LineChart)1 LineConfig (com.android.tools.adtui.chart.linechart.LineConfig)1 AdtUiUtils (com.android.tools.adtui.common.AdtUiUtils)1 DefaultDataSeries (com.android.tools.adtui.model.DefaultDataSeries)1 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)1 SeriesData (com.android.tools.adtui.model.SeriesData)1 JBColor (com.intellij.ui.JBColor)1 JBLayeredPane (com.intellij.ui.components.JBLayeredPane)1 ImmutableList (com.intellij.util.containers.ImmutableList)1 java.awt (java.awt)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 ItemEvent (java.awt.event.ItemEvent)1 Arrays (java.util.Arrays)1 List (java.util.List)1 javax.swing (javax.swing)1 NotNull (org.jetbrains.annotations.NotNull)1