mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Merge pull request #151 from sciamano/freq2
relative size of the marks in the frequency view
This commit is contained in:
@@ -66,6 +66,7 @@ public class FrequencyChart extends ScrollableChart
|
||||
|
||||
@NonNull
|
||||
private HashMap<Long, Integer[]> frequency;
|
||||
private int maxFreq;
|
||||
|
||||
public FrequencyChart(Context context)
|
||||
{
|
||||
@@ -90,9 +91,23 @@ public class FrequencyChart extends ScrollableChart
|
||||
public void setFrequency(HashMap<Long, Integer[]> frequency)
|
||||
{
|
||||
this.frequency = frequency;
|
||||
maxFreq = getMaxFreq(frequency);
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
private int getMaxFreq(HashMap<Long, Integer[]> frequency)
|
||||
{
|
||||
int maxValue = 1;
|
||||
for (Integer[] values : frequency.values())
|
||||
{
|
||||
for (Integer value : values)
|
||||
{
|
||||
maxValue = Math.max(value, maxValue);
|
||||
}
|
||||
}
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
||||
{
|
||||
this.isBackgroundTransparent = isBackgroundTransparent;
|
||||
@@ -235,10 +250,14 @@ public class FrequencyChart extends ScrollableChart
|
||||
private void drawMarker(Canvas canvas, RectF rect, Integer value)
|
||||
{
|
||||
float padding = rect.height() * 0.2f;
|
||||
float radius =
|
||||
(rect.height() - 2 * padding) / 2.0f / 4.0f * Math.min(value, 4);
|
||||
// maximal allowed mark radius
|
||||
float maxRadius = (rect.height() - 2 * padding) / 2.0f;
|
||||
// the real mark radius is scaled down by a factor depending on the maximal frequency
|
||||
float scale = 1.0f/maxFreq * value;
|
||||
float radius = maxRadius * scale;
|
||||
|
||||
pGraph.setColor(colors[Math.min(3, Math.max(0, value - 1))]);
|
||||
int colorIndex = Math.round((colors.length-1) * scale);
|
||||
pGraph.setColor(colors[colorIndex]);
|
||||
canvas.drawCircle(rect.centerX(), rect.centerY(), radius, pGraph);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ public abstract class RepetitionList
|
||||
for (Repetition r : reps)
|
||||
{
|
||||
Calendar date = DateUtils.getCalendar(r.getTimestamp());
|
||||
int weekday = date.get(Calendar.DAY_OF_WEEK) % 7;
|
||||
int weekday = DateUtils.getWeekday(r.getTimestamp());
|
||||
date.set(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
long timestamp = date.getTimeInMillis();
|
||||
|
||||
@@ -206,7 +206,7 @@ public abstract class DateUtils
|
||||
public static int getWeekday(long timestamp)
|
||||
{
|
||||
GregorianCalendar day = getCalendar(timestamp);
|
||||
return day.get(DAY_OF_WEEK) % 7;
|
||||
return javaWeekdayToLoopWeekday(day.get(DAY_OF_WEEK));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user