Java Code Examples for com.github.mikephil.charting.utils.ColorTemplate#COLOR_SKIP

The following examples show how to use com.github.mikephil.charting.utils.ColorTemplate#COLOR_SKIP . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Legend.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * Entries that will be appended to the end of the auto calculated
 * entries after calculating the legend.
 * (if the legend has already been calculated, you will need to call notifyDataSetChanged()
 * to let the changes take effect)
 */
public void setExtra(int[] colors, String[] labels) {

    List<LegendEntry> entries = new ArrayList<>();

    for (int i = 0; i < Math.min(colors.length, labels.length); i++) {
        final LegendEntry entry = new LegendEntry();
        entry.formColor = colors[i];
        entry.label = labels[i];

        if (entry.formColor == ColorTemplate.COLOR_SKIP ||
                entry.formColor == 0) {
            entry.form = LegendForm.NONE;
        } else if (entry.formColor == ColorTemplate.COLOR_NONE) {
            entry.form = LegendForm.EMPTY;
        }

        entries.add(entry);
    }

    mExtraEntries = entries.toArray(new LegendEntry[entries.size()]);
}
 
Example 2
Source File: LegendRenderer.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c     canvas to draw with
 * @param x     position
 * @param y     position
 * @param index the index of the color to use (in the colors array)
 */
protected void drawForm(Canvas c, float x, float y, int index, Legend legend) {

    if (legend.getColors()[index] == ColorTemplate.COLOR_SKIP)
        return;

    mLegendFormPaint.setColor(legend.getColors()[index]);

    float formsize = legend.getFormSize();
    float half = formsize / 2f;

    switch (legend.getForm()) {
        case CIRCLE:
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;
        case SQUARE:
            c.drawRect(x, y - half, x + formsize, y + half, mLegendFormPaint);
            break;
        case LINE:
            c.drawLine(x, y, x + formsize, y, mLegendFormPaint);
            break;
    }
}
 
Example 3
Source File: LegendRenderer.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c     canvas to draw with
 * @param x     position
 * @param y     position
 * @param index the index of the color to use (in the colors array)
 */
protected void drawForm(Canvas c, float x, float y, int index, Legend legend) {

    if (legend.getColors()[index] == ColorTemplate.COLOR_SKIP)
        return;

    mLegendFormPaint.setColor(legend.getColors()[index]);

    float formsize = legend.getFormSize();
    float half = formsize / 2f;

    switch (legend.getForm()) {
        case CIRCLE:
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;
        case SQUARE:
            c.drawRect(x, y - half, x + formsize, y + half, mLegendFormPaint);
            break;
        case LINE:
            c.drawLine(x, y, x + formsize, y, mLegendFormPaint);
            break;
    }
}
 
Example 4
Source File: Legend.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * Entries that will be appended to the end of the auto calculated
 *   entries after calculating the legend.
 * (if the legend has already been calculated, you will need to call notifyDataSetChanged()
 *   to let the changes take effect)
 */
public void setExtra(int[] colors, String[] labels) {

    List<LegendEntry> entries = new ArrayList<>();

    for (int i = 0; i < Math.min(colors.length, labels.length); i++) {
        final LegendEntry entry = new LegendEntry();
        entry.formColor = colors[i];
        entry.label = labels[i];

        if (entry.formColor == ColorTemplate.COLOR_SKIP ||
                entry.formColor == 0)
            entry.form = LegendForm.NONE;
        else if (entry.formColor == ColorTemplate.COLOR_NONE)
            entry.form = LegendForm.EMPTY;

        entries.add(entry);
    }

    mExtraEntries = entries.toArray(new LegendEntry[entries.size()]);
}
 
Example 5
Source File: LegendRenderer.java    From iMoney with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c     canvas to draw with
 * @param x     position
 * @param y     position
 * @param index the index of the color to use (in the colors array)
 */
protected void drawForm(Canvas c, float x, float y, int index, Legend legend) {

    if (legend.getColors()[index] == ColorTemplate.COLOR_SKIP)
        return;

    mLegendFormPaint.setColor(legend.getColors()[index]);

    float formsize = legend.getFormSize();
    float half = formsize / 2f;

    switch (legend.getForm()) {
        case CIRCLE:
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;
        case SQUARE:
            c.drawRect(x, y - half, x + formsize, y + half, mLegendFormPaint);
            break;
        case LINE:
            c.drawLine(x, y, x + formsize, y, mLegendFormPaint);
            break;
    }
}
 
Example 6
Source File: Legend.java    From android-kline with Apache License 2.0 6 votes vote down vote up
/**
 * Entries that will be appended to the end of the auto calculated
 *   entries after calculating the legend.
 * (if the legend has already been calculated, you will need to call notifyDataSetChanged()
 *   to let the changes take effect)
 */
public void setExtra(int[] colors, String[] labels) {

    List<LegendEntry> entries = new ArrayList<>();

    for (int i = 0; i < Math.min(colors.length, labels.length); i++) {
        final LegendEntry entry = new LegendEntry();
        entry.formColor = colors[i];
        entry.label = labels[i];

        if (entry.formColor == ColorTemplate.COLOR_SKIP ||
                entry.formColor == 0)
            entry.form = LegendForm.NONE;
        else if (entry.formColor == ColorTemplate.COLOR_NONE)
            entry.form = LegendForm.EMPTY;

        entries.add(entry);
    }

    mExtraEntries = entries.toArray(new LegendEntry[entries.size()]);
}
 
Example 7
Source File: Legend.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * calculates the full width the fully drawn legend will use in pixels
 * 
 * @return
 */
public float getFullWidth(Paint labelpaint) {

    float width = 0f;

    for (int i = 0; i < mLabels.length; i++) {

        // grouped forms have null labels
        if (mLabels[i] != null) {

            // make a step to the left
            if (mColors[i] != ColorTemplate.COLOR_SKIP)
                width += mFormSize + mFormToTextSpace;

            width += Utils.calcTextWidth(labelpaint, mLabels[i]);

            if (i < mLabels.length - 1)
                width += mXEntrySpace;
        } else {
            width += mFormSize;
            if (i < mLabels.length - 1)
                width += mStackSpace;
        }
    }

    return width;
}
 
Example 8
Source File: Legend.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * calculates the full width the fully drawn legend will use in pixels
 * 
 * @return
 */
public float getFullWidth(Paint labelpaint) {

    float width = 0f;

    for (int i = 0; i < mLabels.length; i++) {

        // grouped forms have null labels
        if (mLabels[i] != null) {

            // make a step to the left
            if (mColors[i] != ColorTemplate.COLOR_SKIP)
                width += mFormSize + mFormToTextSpace;

            width += Utils.calcTextWidth(labelpaint, mLabels[i]);

            if (i < mLabels.length - 1)
                width += mXEntrySpace;
        } else {
            width += mFormSize;
            if (i < mLabels.length - 1)
                width += mStackSpace;
        }
    }

    return width;
}
 
Example 9
Source File: Legend.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * calculates the full width the fully drawn legend will use in pixels
 * 
 * @return
 */
public float getFullWidth(Paint labelpaint) {

    float width = 0f;

    for (int i = 0; i < mLabels.length; i++) {

        // grouped forms have null labels
        if (mLabels[i] != null) {

            // make a step to the left
            if (mColors[i] != ColorTemplate.COLOR_SKIP)
                width += mFormSize + mFormToTextSpace;

            width += Utils.calcTextWidth(labelpaint, mLabels[i]);

            if (i < mLabels.length - 1)
                width += mXEntrySpace;
        } else {
            width += mFormSize;
            if (i < mLabels.length - 1)
                width += mStackSpace;
        }
    }

    return width;
}
 
Example 10
Source File: Legend.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Deprecated
public int[] getExtraColors() {

    int[] old = new int[mExtraEntries.length];
    for (int i = 0; i < mExtraEntries.length; i++) {
        old[i] = mExtraEntries[i].form == LegendForm.NONE ? ColorTemplate.COLOR_SKIP :
                (mExtraEntries[i].form == LegendForm.EMPTY ? ColorTemplate.COLOR_NONE :
                        mExtraEntries[i].formColor);
    }
    return old;
}
 
Example 11
Source File: Legend.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Deprecated
public int[] getColors() {

    int[] old = new int[mEntries.length];
    for (int i = 0; i < mEntries.length; i++) {
        old[i] = mEntries[i].form == LegendForm.NONE ? ColorTemplate.COLOR_SKIP :
                (mEntries[i].form == LegendForm.EMPTY ? ColorTemplate.COLOR_NONE :
                        mEntries[i].formColor);
    }
    return old;
}
 
Example 12
Source File: Legend.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Deprecated
public Legend(int[] colors, String[] labels) {
    this();

    if (colors == null || labels == null) {
        throw new IllegalArgumentException("colors array or labels array is NULL");
    }

    if (colors.length != labels.length) {
        throw new IllegalArgumentException(
                "colors array and labels array need to be of same size");
    }

    List<LegendEntry> entries = new ArrayList<>();

    for (int i = 0; i < Math.min(colors.length, labels.length); i++) {
        final LegendEntry entry = new LegendEntry();
        entry.formColor = colors[i];
        entry.label = labels[i];

        if (entry.formColor == ColorTemplate.COLOR_SKIP)
            entry.form = LegendForm.NONE;
        else if (entry.formColor == ColorTemplate.COLOR_NONE ||
                entry.formColor == 0)
            entry.form = LegendForm.EMPTY;

        entries.add(entry);
    }

    mEntries = entries.toArray(new LegendEntry[entries.size()]);
}
 
Example 13
Source File: Legend.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Deprecated
public int[] getExtraColors() {

    int[] old = new int[mExtraEntries.length];
    for (int i = 0; i < mExtraEntries.length; i++) {
        old[i] = mExtraEntries[i].form == LegendForm.NONE ? ColorTemplate.COLOR_SKIP :
                (mExtraEntries[i].form == LegendForm.EMPTY ? ColorTemplate.COLOR_NONE :
                        mExtraEntries[i].formColor);
    }
    return old;
}
 
Example 14
Source File: Legend.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Deprecated
public int[] getColors() {

    int[] old = new int[mEntries.length];
    for (int i = 0; i < mEntries.length; i++) {
        old[i] = mEntries[i].form == LegendForm.NONE ? ColorTemplate.COLOR_SKIP :
                (mEntries[i].form == LegendForm.EMPTY ? ColorTemplate.COLOR_NONE :
                        mEntries[i].formColor);
    }
    return old;
}
 
Example 15
Source File: Legend.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Deprecated
public Legend(int[] colors, String[] labels) {
    this();

    if (colors == null || labels == null) {
        throw new IllegalArgumentException("colors array or labels array is NULL");
    }

    if (colors.length != labels.length) {
        throw new IllegalArgumentException(
                "colors array and labels array need to be of same size");
    }

    List<LegendEntry> entries = new ArrayList<>();

    for (int i = 0; i < Math.min(colors.length, labels.length); i++) {
        final LegendEntry entry = new LegendEntry();
        entry.formColor = colors[i];
        entry.label = labels[i];

        if (entry.formColor == ColorTemplate.COLOR_SKIP)
            entry.form = LegendForm.NONE;
        else if (entry.formColor == ColorTemplate.COLOR_NONE ||
                entry.formColor == 0)
            entry.form = LegendForm.EMPTY;

        entries.add(entry);
    }

    mEntries = entries.toArray(new LegendEntry[entries.size()]);
}
 
Example 16
Source File: LegendRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c      canvas to draw with
 * @param x      position
 * @param y      position
 * @param entry  the entry to render
 * @param legend the legend context
 */
protected void drawForm(
        Canvas c,
        float x, float y,
        LegendEntry entry,
        Legend legend) {

    if (entry.formColor == ColorTemplate.COLOR_SKIP ||
            entry.formColor == ColorTemplate.COLOR_NONE ||
            entry.formColor == 0)
        return;

    int restoreCount = c.save();

    Legend.LegendForm form = entry.form;
    if (form == Legend.LegendForm.DEFAULT)
        form = legend.getForm();

    mLegendFormPaint.setColor(entry.formColor);

    final float formSize = Utils.convertDpToPixel(
            Float.isNaN(entry.formSize)
                    ? legend.getFormSize()
                    : entry.formSize);
    final float half = formSize / 2f;

    switch (form) {
        case NONE:
            // Do nothing
            break;

        case EMPTY:
            // Do not draw, but keep space for the form
            break;

        case DEFAULT:
        case CIRCLE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;

        case SQUARE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawRect(x, y - half, x + formSize, y + half, mLegendFormPaint);
            break;

        case LINE:
        {
            final float formLineWidth = Utils.convertDpToPixel(
                    Float.isNaN(entry.formLineWidth)
                            ? legend.getFormLineWidth()
                            : entry.formLineWidth);
            final DashPathEffect formLineDashEffect = entry.formLineDashEffect == null
                    ? legend.getFormLineDashEffect()
                    : entry.formLineDashEffect;
            mLegendFormPaint.setStyle(Paint.Style.STROKE);
            mLegendFormPaint.setStrokeWidth(formLineWidth);
            mLegendFormPaint.setPathEffect(formLineDashEffect);

            mLineFormPath.reset();
            mLineFormPath.moveTo(x, y);
            mLineFormPath.lineTo(x + formSize, y);
            c.drawPath(mLineFormPath, mLegendFormPaint);
        }
            break;
    }

    c.restoreToCount(restoreCount);
}
 
Example 17
Source File: LegendRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c      canvas to draw with
 * @param x      position
 * @param y      position
 * @param entry  the entry to render
 * @param legend the legend context
 */
protected void drawForm(
        Canvas c,
        float x, float y,
        LegendEntry entry,
        Legend legend) {

    if (entry.formColor == ColorTemplate.COLOR_SKIP ||
            entry.formColor == ColorTemplate.COLOR_NONE ||
            entry.formColor == 0)
        return;

    int restoreCount = c.save();

    Legend.LegendForm form = entry.form;
    if (form == Legend.LegendForm.DEFAULT)
        form = legend.getForm();

    mLegendFormPaint.setColor(entry.formColor);

    final float formSize = Utils.convertDpToPixel(
            Float.isNaN(entry.formSize)
                    ? legend.getFormSize()
                    : entry.formSize);
    final float half = formSize / 2f;

    switch (form) {
        case NONE:
            // Do nothing
            break;

        case EMPTY:
            // Do not draw, but keep space for the form
            break;

        case DEFAULT:
        case CIRCLE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;

        case SQUARE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawRect(x, y - half, x + formSize, y + half, mLegendFormPaint);
            break;

        case LINE:
        {
            final float formLineWidth = Utils.convertDpToPixel(
                    Float.isNaN(entry.formLineWidth)
                            ? legend.getFormLineWidth()
                            : entry.formLineWidth);
            final DashPathEffect formLineDashEffect = entry.formLineDashEffect == null
                    ? legend.getFormLineDashEffect()
                    : entry.formLineDashEffect;
            mLegendFormPaint.setStyle(Paint.Style.STROKE);
            mLegendFormPaint.setStrokeWidth(formLineWidth);
            mLegendFormPaint.setPathEffect(formLineDashEffect);

            mLineFormPath.reset();
            mLineFormPath.moveTo(x, y);
            mLineFormPath.lineTo(x + formSize, y);
            c.drawPath(mLineFormPath, mLegendFormPaint);
        }
            break;
    }

    c.restoreToCount(restoreCount);
}
 
Example 18
Source File: LegendRenderer.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c      canvas to draw with
 * @param x      position
 * @param y      position
 * @param entry  the entry to render
 * @param legend the legend context
 */
protected void drawForm(
        Canvas c,
        float x, float y,
        LegendEntry entry,
        Legend legend) {

    if (entry.formColor == ColorTemplate.COLOR_SKIP ||
            entry.formColor == ColorTemplate.COLOR_NONE ||
            entry.formColor == 0) {
        return;
    }

    int restoreCount = c.save();

    Legend.LegendForm form = entry.form;
    if (form == Legend.LegendForm.DEFAULT) {
        form = legend.getForm();
    }

    mLegendFormPaint.setColor(entry.formColor);

    final float formSize = Utils.convertDpToPixel(
            Float.isNaN(entry.formSize)
                    ? legend.getFormSize()
                    : entry.formSize);
    final float half = formSize / 2f;

    switch (form) {
        case NONE:
            // Do nothing
            break;

        case EMPTY:
            // Do not draw, but keep space for the form
            break;

        case DEFAULT:
        case CIRCLE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;

        case SQUARE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawRect(x, y - half, x + formSize, y + half, mLegendFormPaint);
            break;

        case LINE: {
            final float formLineWidth = Utils.convertDpToPixel(
                    Float.isNaN(entry.formLineWidth)
                            ? legend.getFormLineWidth()
                            : entry.formLineWidth);
            final DashPathEffect formLineDashEffect = entry.formLineDashEffect == null
                    ? legend.getFormLineDashEffect()
                    : entry.formLineDashEffect;
            mLegendFormPaint.setStyle(Paint.Style.STROKE);
            mLegendFormPaint.setStrokeWidth(formLineWidth);
            mLegendFormPaint.setPathEffect(formLineDashEffect);

            mLineFormPath.reset();
            mLineFormPath.moveTo(x, y);
            mLineFormPath.lineTo(x + formSize, y);
            c.drawPath(mLineFormPath, mLegendFormPaint);
        }
        break;
    }

    c.restoreToCount(restoreCount);
}