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);
}
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)));
}
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;
}
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();
}
});
}
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();
}
});
}
Aggregations