Search in sources :

Example 1 with LineChart

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

the class BaseLineChartSegment method createComponentsList.

@Override
public void createComponentsList(@NotNull List<Animatable> animatables) {
    // left axis
    AxisComponent.Builder builder = new AxisComponent.Builder(mLeftAxisRange, mLeftAxisFormatterSimple, AxisComponent.AxisOrientation.LEFT).showMax(true).clampToMajorTicks(true);
    mLeftAxis = builder.build();
    // right axis
    if (mRightAxisFormatter != null) {
        builder = new AxisComponent.Builder(mRightAxisRange, mRightAxisFormatter, AxisComponent.AxisOrientation.RIGHT).showMax(true).setParentAxis(mLeftAxis);
        mRightAxis = builder.build();
        mRightAxis.setParentAxis(mLeftAxis);
        mRightAxis.setVisible(false);
    }
    mLineChart = new LineChart();
    mGrid = new GridComponent();
    mGrid.addAxis(mLeftAxis);
    mGrid.setVisible(false);
    mLegendComponent = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, 100);
    // Note: the order below is important as some components depend on
    // others to be updated first. e.g. the ranges need to be updated before the axes.
    // The comment on each line highlights why the component needs to be in that position.
    // Set y's interpolation values.
    animatables.add(mLineChart);
    // Read left y range and update its max to the next major tick.
    animatables.add(mLeftAxis);
    if (mRightAxis != null) {
        // Read right y range and update its max by syncing to the left axis' major tick spacing.
        animatables.add(mRightAxis);
    }
    // Interpolate left y range.
    animatables.add(mLeftAxisRange);
    // Interpolate right y range.
    animatables.add(mRightAxisRange);
    animatables.add(mLegendComponent);
    // No-op.
    animatables.add(mGrid);
}
Also used : LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Example 2 with LineChart

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

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

the class AccordionVisualTest method generateChart.

@NotNull
private LineChart generateChart(AccordionLayout layout, AccordionLayout.Orientation direction, int minSize, int preferredSize, int maxSize) {
    LineChart chart = new LineChart(mRangedData);
    if (direction == AccordionLayout.Orientation.VERTICAL) {
        chart.setMinimumSize(new Dimension(0, minSize));
        chart.setPreferredSize(new Dimension(0, preferredSize));
        chart.setMaximumSize(new Dimension(0, maxSize));
    } else {
        chart.setMinimumSize(new Dimension(minSize, 0));
        chart.setPreferredSize(new Dimension(preferredSize, 0));
        chart.setMaximumSize(new Dimension(maxSize, 0));
    }
    chart.setBorder(BorderFactory.createLineBorder(Color.GRAY));
    chart.setToolTipText("Double-click to maximize. Ctrl+Double-click to minimize.");
    chart.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == DOUBLE_CLICK) {
                if (e.isControlDown()) {
                    layout.toggleMinimize(chart);
                } else {
                    layout.toggleMaximize(chart);
                }
            }
        }
    });
    addToChoreographer(chart);
    return chart;
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) LineChart(com.android.tools.adtui.chart.linechart.LineChart) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with LineChart

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

the class CpuMonitorView method populateUi.

@Override
protected void populateUi(JPanel container, Choreographer choreographer) {
    container.setLayout(new TabularLayout("*", "*"));
    Range viewRange = getMonitor().getTimeline().getViewRange();
    Range dataRange = getMonitor().getTimeline().getDataRange();
    final JLabel label = new JLabel(getMonitor().getName());
    label.setBorder(MONITOR_LABEL_PADDING);
    label.setVerticalAlignment(JLabel.TOP);
    // Cpu usage is shown as percentages (e.g. 0 - 100) and no range animation is needed.
    Range leftYRange = new Range(0, 100);
    final JPanel axisPanel = new JBPanel(new BorderLayout());
    axisPanel.setOpaque(false);
    AxisComponent.Builder builder = new AxisComponent.Builder(leftYRange, CPU_USAGE_AXIS, 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 = builder.build();
    axisPanel.add(leftAxis, BorderLayout.WEST);
    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();
    RangedContinuousSeries cpuSeries = new RangedContinuousSeries("CPU", viewRange, leftYRange, getMonitor().getThisProcessCpuUsage());
    lineChart.addLine(cpuSeries, new LineConfig(ProfilerColors.CPU_USAGE).setFilled(true));
    lineChartPanel.add(lineChart, BorderLayout.CENTER);
    final LegendComponent legend = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, LEGEND_UPDATE_FREQUENCY_MS);
    legend.setLegendData(Collections.singletonList(lineChart.createLegendRenderData(cpuSeries, CPU_USAGE_AXIS, dataRange)));
    final JPanel legendPanel = new JBPanel(new BorderLayout());
    legendPanel.setOpaque(false);
    legendPanel.add(label, BorderLayout.WEST);
    legendPanel.add(legend, BorderLayout.EAST);
    choreographer.register(lineChart);
    choreographer.register(leftAxis);
    choreographer.register(legend);
    container.add(legendPanel, new TabularLayout.Constraint(0, 0));
    container.add(leftAxis, new TabularLayout.Constraint(0, 0));
    container.add(lineChartPanel, new TabularLayout.Constraint(0, 0));
    container.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            getMonitor().expand();
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) TabularLayout(com.android.tools.adtui.TabularLayout) MouseAdapter(java.awt.event.MouseAdapter) AxisComponent(com.android.tools.adtui.AxisComponent) Range(com.android.tools.adtui.model.Range) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) JBPanel(com.intellij.ui.components.JBPanel) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LegendComponent(com.android.tools.adtui.LegendComponent) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Example 5 with LineChart

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

the class MemoryMonitorView method populateUi.

@Override
protected void populateUi(JPanel container, Choreographer choreographer) {
    container.setLayout(new TabularLayout("*", "*"));
    Range viewRange = getMonitor().getTimeline().getViewRange();
    Range dataRange = getMonitor().getTimeline().getDataRange();
    final JLabel label = new JLabel(getMonitor().getName());
    label.setBorder(MONITOR_LABEL_PADDING);
    label.setVerticalAlignment(JLabel.TOP);
    Range leftYRange = new Range(0, 0);
    final JPanel axisPanel = new JBPanel(new BorderLayout());
    axisPanel.setOpaque(false);
    AxisComponent.Builder builder = 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 = builder.build();
    axisPanel.add(leftAxis, BorderLayout.WEST);
    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();
    RangedContinuousSeries memSeries = new RangedContinuousSeries("Memory", viewRange, leftYRange, getMonitor().getTotalMemory());
    lineChart.addLine(memSeries, new LineConfig(ProfilerColors.MEMORY_TOTAL).setFilled(true));
    lineChartPanel.add(lineChart, BorderLayout.CENTER);
    final LegendComponent legend = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, LEGEND_UPDATE_FREQUENCY_MS);
    legend.setLegendData(Collections.singletonList(lineChart.createLegendRenderData(memSeries, MEMORY_AXIS_FORMATTER, dataRange)));
    final JPanel legendPanel = new JBPanel(new BorderLayout());
    legendPanel.setOpaque(false);
    legendPanel.add(label, BorderLayout.WEST);
    legendPanel.add(legend, BorderLayout.EAST);
    choreographer.register(lineChart);
    choreographer.register(leftAxis);
    choreographer.register(legend);
    container.add(legendPanel, new TabularLayout.Constraint(0, 0));
    container.add(leftAxis, new TabularLayout.Constraint(0, 0));
    container.add(lineChartPanel, new TabularLayout.Constraint(0, 0));
    container.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            getMonitor().expand();
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) TabularLayout(com.android.tools.adtui.TabularLayout) MouseAdapter(java.awt.event.MouseAdapter) AxisComponent(com.android.tools.adtui.AxisComponent) Range(com.android.tools.adtui.model.Range) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) JBPanel(com.intellij.ui.components.JBPanel) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LegendComponent(com.android.tools.adtui.LegendComponent) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

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