use of com.android.tools.adtui.model.SeriesData in project android by JetBrains.
the class LineChart method updateData.
@Override
protected void updateData() {
Map<Range, Double> max = new HashMap<>();
// TODO Handle stacked configs
for (RangedContinuousSeries ranged : myLinesConfig.keySet()) {
Range range = ranged.getYRange();
double yMax = Double.MIN_VALUE;
ImmutableList<SeriesData<Long>> seriesList = ranged.getSeries();
for (int i = 0; i < seriesList.size(); i++) {
double value = seriesList.get(i).value;
if (yMax < value) {
yMax = value;
}
}
Double m = max.get(range);
max.put(range, m == null ? yMax : Math.max(yMax, m));
}
for (Map.Entry<Range, Double> entry : max.entrySet()) {
Range range = entry.getKey();
// Prevent the LineChart to update the range below its current max.
if (range.getMax() < entry.getValue()) {
float fraction = myFirstUpdate ? 1f : DEFAULT_LERP_FRACTION;
range.setMax(Choreographer.lerp(range.getMax(), entry.getValue(), fraction, mFrameLength, (float) (entry.getValue() * DEFAULT_LERP_THRESHOLD_PERCENTAGE)));
}
}
myFirstUpdate = false;
}
use of com.android.tools.adtui.model.SeriesData 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.model.SeriesData in project android by JetBrains.
the class AxisLineChartVisualTest method populateUi.
@Override
protected void populateUi(@NotNull JPanel panel) {
panel.setLayout(new BorderLayout());
JLayeredPane mockTimelinePane = createMockTimeline();
panel.add(mockTimelinePane, BorderLayout.CENTER);
final JBPanel controls = new JBPanel();
LayoutManager manager = new BoxLayout(controls, BoxLayout.Y_AXIS);
controls.setLayout(manager);
panel.add(controls, BorderLayout.WEST);
final AtomicInteger variance = new AtomicInteger(10);
final AtomicInteger delay = new AtomicInteger(10);
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(delay.get());
}
} catch (InterruptedException e) {
}
}
};
mUpdateDataThread.start();
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("Variance", 0, 50, new VisualTests.Value() {
@Override
public void set(int v) {
variance.set(v);
}
@Override
public int get() {
return variance.get();
}
}));
controls.add(VisualTest.createCheckbox("Stable Scroll", itemEvent -> mScrollbar.setStableScrolling(itemEvent.getStateChange() == ItemEvent.SELECTED)));
controls.add(VisualTest.createCheckbox("Clamp To Major Ticks", itemEvent -> mMemoryAxis1.setClampToMajorTicks(itemEvent.getStateChange() == ItemEvent.SELECTED)));
controls.add(VisualTest.createCheckbox("Sync Vertical Axes", itemEvent -> mMemoryAxis2.setParentAxis(itemEvent.getStateChange() == ItemEvent.SELECTED ? mMemoryAxis1 : null)));
controls.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.model.SeriesData in project android by JetBrains.
the class CpuMonitorTest method testOtherProcessesCpuUsage.
@Test
public void testOtherProcessesCpuUsage() throws IOException {
CpuUsageDataSeries series = myMonitor.getOtherProcessesCpuUsage();
ImmutableList<SeriesData<Long>> seriesDataList = series.getDataForXRange(new Range());
// Only other processes information.
assertEquals(1, seriesDataList.size());
SeriesData<Long> seriesData = seriesDataList.get(0);
assertNotNull(seriesData);
assertEquals(40, (long) seriesData.value);
}
use of com.android.tools.adtui.model.SeriesData in project android by JetBrains.
the class CpuMonitorTest method testThisProcessCpuUsage.
@Test
public void testThisProcessCpuUsage() throws IOException {
CpuUsageDataSeries series = myMonitor.getThisProcessCpuUsage();
ImmutableList<SeriesData<Long>> seriesDataList = series.getDataForXRange(new Range());
// Only current process information.
assertEquals(1, seriesDataList.size());
SeriesData<Long> seriesData = seriesDataList.get(0);
assertNotNull(seriesData);
assertEquals(20, (long) seriesData.value);
}
Aggregations