Search in sources :

Example 1 with LineChartLine

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);
}
Also used : Delta(com.nolanlawson.keepscore.db.Delta) ArrayList(java.util.ArrayList) LineChartLine(com.nolanlawson.keepscore.widget.chart.LineChartLine) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 2 with LineChartLine

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);
}
Also used : ArrayList(java.util.ArrayList) LineChartLine(com.nolanlawson.keepscore.widget.chart.LineChartLine) SparseArray(android.util.SparseArray) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Aggregations

PlayerScore (com.nolanlawson.keepscore.db.PlayerScore)2 LineChartLine (com.nolanlawson.keepscore.widget.chart.LineChartLine)2 ArrayList (java.util.ArrayList)2 SparseArray (android.util.SparseArray)1 Delta (com.nolanlawson.keepscore.db.Delta)1