use of com.nolanlawson.keepscore.widget.chart.LineChartLine in project KeepScore by nolanlawson.
the class HistoryRoundChartFragment method createByChartLayout.
private void createByChartLayout(Activity activity) {
List<LineChartLine> data = new ArrayList<LineChartLine>();
for (PlayerScore playerScore : game.getPlayerScores()) {
List<Integer> dataPoints = new ArrayList<Integer>();
// have to include the starting score as well
long runningTally = playerScore.getScore() - CollectionUtil.sum(CollectionUtil.transform(playerScore.getHistory(), Delta.GET_VALUE));
dataPoints.add((int) runningTally);
for (Delta delta : playerScore.getHistory()) {
runningTally += delta.getValue();
dataPoints.add((int) runningTally);
}
LineChartLine line = new LineChartLine();
line.setDataPoints(dataPoints);
line.setLabel(playerScore.toDisplayName(activity).toString());
data.add(line);
}
byRoundLineChartView.setLineColors(createLineColors(game, activity));
byRoundLineChartView.loadData(data);
}
use of com.nolanlawson.keepscore.widget.chart.LineChartLine in project KeepScore by nolanlawson.
the class HistoryTimelineFragment method createTimelineLayout.
private void createTimelineLayout(Activity activity) {
List<String> xAxisLabels = new ArrayList<String>();
SparseArray<SparseArray<Long>> smoothedData = smoothData(game);
List<LineChartLine> data = new ArrayList<LineChartLine>();
for (PlayerScore playerScore : game.getPlayerScores()) {
data.add(new LineChartLine(playerScore.toDisplayName(activity).toString(), new ArrayList<Integer>()));
}
long[] lastPlayerScores = new long[game.getPlayerScores().size()];
for (int i = 0; i < smoothedData.size(); i++) {
int timeSinceStart = smoothedData.keyAt(i);
xAxisLabels.add(TimeUtil.formatSeconds(timeSinceStart));
SparseArray<Long> scores = smoothedData.get(timeSinceStart);
for (int playerIdx = 0; playerIdx < game.getPlayerScores().size(); playerIdx++) {
Long scoreObj = scores.get(playerIdx);
// just give the player a zero-delta (i.e. previous score) for this "round" if no changes
long score = scoreObj == null ? lastPlayerScores[playerIdx] : scoreObj;
List<Integer> dataPoints = data.get(playerIdx).getDataPoints();
dataPoints.add((int) score);
lastPlayerScores[playerIdx] = score;
}
}
timelineChartView.setLineColors(createLineColors(game, activity));
timelineChartView.setxAxisLabels(xAxisLabels);
log.d("x labels are %s", xAxisLabels);
timelineChartView.loadData(data);
}
Aggregations