package org.hogel.android.linechartview;

import android.content.Context;
import android.text.format.DateFormat;

import java.util.ArrayList;
import java.util.List;

public class DateLineChartView extends LineChartView {

    private static final long HALF_DAY = 12 * 60 * 60 * 1000;

    private static final long A_DAY = 24 * 60 * 60 * 1000;

    public DateLineChartView(Context context) {
        this(context, new ArrayList<Point>());
    }

    public DateLineChartView(Context context, List<Point> points) {
        this(context, points, new LineChartStyle());
    }

    public DateLineChartView(Context context, List<Point> points, LineChartStyle lineChartStyle) {
        super(context, points, lineChartStyle);
    }

    public DateLineChartView(Context context, LineChartStyle lineChartStyle) {
        super(context, new ArrayList<Point>(), lineChartStyle);
    }

    @Override
    protected String formatXLabel(long x) {
        if (lineChartStyle.getXLabelFormatter() != null) {
            return lineChartStyle.getXLabelFormatter().format(x);
        }
        return DateFormat.format("yyyy/M/d", x).toString();
    }

    @Override
    public long getMinX() {
        return getRawMinX() - HALF_DAY;
    }

    @Override
    public long getMaxX() {
        return getRawMaxX() + HALF_DAY;
    }

    @Override
    public long getRawMinX() {
        if (points.isEmpty()) {
            return (System.currentTimeMillis() / A_DAY - 7) * A_DAY;
        }
        return super.getRawMinX();
    }

    @Override
    protected long getRawMaxX() {
        if (points.isEmpty()) {
            return (System.currentTimeMillis() / A_DAY) * A_DAY;
        }
        return super.getRawMaxX();
    }

    @Override
    public long getMinY() {
        return 0;
    }

    @Override
    public long getXGridUnit() {
        if (manualXGridUnit != null) {
            return manualXGridUnit;
        }
        return A_DAY;
    }
}

@@ -1166,18 +1166,18 @@
 ong getM
-in
+ax
 X() %7B%0A  
@@ -1186,88 +1186,74 @@
     
-return getRawMinX() - HALF_DAY;
+if (manualMaxX != null) %7B
 %0A    
-%7D%0A%0A
     
-@Override%0A    public long getMaxX() %7B
+    return manualMaxX;%0A        %7D
 %0A   
@@ -1729,24 +1729,99 @@
 getMinY() %7B%0A
+        if (manualMinY != null) %7B%0A            return manualMinY;%0A        %7D%0A
         retu
@@ -1992,11 +1992,115 @@
 Y;%0A    %7D
+%0A%0A    @Override%0A    protected long calcMinGridValue(long min, long gridUnit) %7B%0A        return min;%0A    %7D
 %0A%7D%0A

Remove left margin in date chart