use of com.android.tools.adtui.model.SeriesData in project android by JetBrains.
the class LineChart method postAnimate.
@Override
public void postAnimate() {
long duration = System.nanoTime();
int p = 0;
// Store the Y coordinates of the last stacked series to use them to increment the Y values
// of the current stacked series.
TDoubleArrayList lastStackedSeriesY = null;
Deque<Path2D> orderedPaths = new ArrayDeque<>(myLinesConfig.size());
Deque<LineConfig> orderedConfigs = new ArrayDeque<>(myLinesConfig.size());
for (Map.Entry<RangedContinuousSeries, LineConfig> lineConfig : myLinesConfig.entrySet()) {
final RangedContinuousSeries ranged = lineConfig.getKey();
final LineConfig config = lineConfig.getValue();
// Stores the y coordinates of the current series in case it's used as a stacked series
final TDoubleArrayList currentSeriesY = new TDoubleArrayList();
Path2D path = new Path2D.Float();
double xMin = ranged.getXRange().getMin();
double xMax = ranged.getXRange().getMax();
double yMin = ranged.getYRange().getMin();
double yMax = ranged.getYRange().getMax();
// X coordinate of the first point
double firstXd = 0f;
List<SeriesData<Long>> seriesList = ranged.getSeries();
for (int i = 0; i < seriesList.size(); i++) {
// TODO: refactor to allow different types (e.g. double)
SeriesData<Long> seriesData = seriesList.get(i);
long currX = seriesData.x;
long currY = seriesData.value;
double xd = (currX - xMin) / (xMax - xMin);
double yd = (currY - yMin) / (yMax - yMin);
// prior iteration). In this case, yd of the current series shouldn't change.
if (config.isStacked() && lastStackedSeriesY != null && i < lastStackedSeriesY.size()) {
yd += lastStackedSeriesY.get(i);
}
currentSeriesY.add(yd);
// Swing's (0, 0) coordinate is in top-left. As we use bottom-left (0, 0), we need to adjust the y coordinate.
float adjustedYd = 1 - (float) yd;
if (i == 0) {
path.moveTo(xd, adjustedYd);
firstXd = xd;
} else {
// drawing a line to the destination point itself (e.g. (x1, y1)).
if (config.isStepped()) {
float y = (float) path.getCurrentPoint().getY();
path.lineTo(xd, y);
}
path.lineTo(xd, adjustedYd);
}
}
if (config.isFilled() && path.getCurrentPoint() != null) {
// If the chart is filled, but not stacked, draw a line from the last point to X
// axis and another one from this new point to the first destination point.
path.lineTo(path.getCurrentPoint().getX(), 1f);
path.lineTo(firstXd, 1f);
}
if (config.isStacked()) {
lastStackedSeriesY = currentSeriesY;
}
if (config.isFilled()) {
// Draw the filled lines first, otherwise other lines won't be visible.
// Also, to draw stacked and filled lines correctly, they need to be drawn in reverse order to their adding order.
orderedPaths.addFirst(path);
orderedConfigs.addFirst(config);
} else {
orderedPaths.addLast(path);
orderedConfigs.addLast(config);
}
addDebugInfo("Range[%d] Max: %.2f", p, xMax);
p++;
}
myLinePaths.clear();
myLinePaths.addAll(orderedPaths);
myLinePathConfigs.clear();
myLinePathConfigs.addAll(orderedConfigs);
addDebugInfo("postAnimate time: %d ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - duration));
}
use of com.android.tools.adtui.model.SeriesData in project android by JetBrains.
the class LineChartLegendRenderData method getFormattedData.
@Override
public String getFormattedData() {
double time = myRange.getMax();
ImmutableList<SeriesData<Long>> data = mySeries.getDataSeries().getDataForXRange(new Range(time, time));
if (data.isEmpty()) {
return null;
}
SeriesData<Long> key = new SeriesData<>(TimeUnit.MICROSECONDS.toNanos((long) time), 0L);
int index = Collections.binarySearch(data, key, (left, right) -> {
long diff = left.x - right.x;
return (diff == 0) ? 0 : (diff < 0) ? -1 : 1;
});
// This returns the data to the right given no exact match.
index = index >= 0 ? index : -(index + 1);
index = Math.max(0, Math.min(data.size() - 1, index));
return myFormatter.getFormattedString(mySeries.getYRange().getLength(), data.get(index).value, true);
}
use of com.android.tools.adtui.model.SeriesData in project android by JetBrains.
the class MemoryDataSeries method getDataForXRange.
@Override
public ImmutableList<SeriesData<Long>> getDataForXRange(@NotNull Range timeCurrentRangeUs) {
// TODO: Change the Memory API to allow specifying padding in the request as number of samples.
long bufferNs = TimeUnit.SECONDS.toNanos(1);
MemoryProfiler.MemoryRequest.Builder dataRequestBuilder = MemoryProfiler.MemoryRequest.newBuilder().setAppId(myProcessId).setStartTime(TimeUnit.MICROSECONDS.toNanos((long) timeCurrentRangeUs.getMin()) - bufferNs).setEndTime(TimeUnit.MICROSECONDS.toNanos((long) timeCurrentRangeUs.getMax()) + bufferNs);
MemoryProfiler.MemoryData response = myClient.getData(dataRequestBuilder.build());
List<SeriesData<Long>> seriesData = new ArrayList<>();
for (MemoryProfiler.MemoryData.MemorySample sample : response.getMemSamplesList()) {
long dataTimestamp = TimeUnit.NANOSECONDS.toMicros(sample.getTimestamp());
seriesData.add(new SeriesData<>(dataTimestamp, myFilter.apply(sample)));
}
return ContainerUtil.immutableList(seriesData);
}
use of com.android.tools.adtui.model.SeriesData in project android by JetBrains.
the class CpuMonitorTest method testGetThreadsCount.
@Test
public void testGetThreadsCount() throws IOException {
CpuThreadCountDataSeries series = myMonitor.getThreadsCount();
ImmutableList<SeriesData<Long>> seriesDataList = series.getDataForXRange(new Range());
assertEquals(1, seriesDataList.size());
SeriesData<Long> seriesData = seriesDataList.get(0);
assertNotNull(seriesData);
// No active threads
assertEquals(0, (long) seriesData.value);
}
Aggregations