Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix circles inherit alpha #2620 #2622

Merged
merged 1 commit into from
Feb 21, 2017
Merged

Fix circles inherit alpha #2620 #2622

merged 1 commit into from
Feb 21, 2017

Conversation

patrick-elmquist
Copy link
Contributor

Issue (#2620) :
When using multiple LineDataSets like the follows:

int solidColor = 0xFFFF00FF;
dataSet.setColor(solidColor);
dataSet.setCircleColor(solidColor);

int semiTransparentColor = 0x8A000000;
fadedSet.setColor(semiTransparentColor);

LineData data = new LineData(dataSet, fadedSet);

the circles in dataSet will rendered with the alpha from fadedSet (0x8A).

The reason for this is that mRenderPaint is not reset properly before drawing the circles. The first time drawCircles(...) is called the imageCache.fill(...) method is used where the color is set by mRenderPaint.setColor(set.getCircleColor(i)), restoring the alpha to 0xFF. The second time homever, imageCache.fill(...) is not called which means that mRenderPaint will use it's old color/alpha, which in this case is from fadedSet.

Test info:
To trigger the issue, add the following to LineChartActivity1:

final ArrayList<Entry> fadedEntries = new ArrayList<>();
for (int i = 0; i < count; i++) {

    float val = (float) (Math.random() * range) + 3;
    fadedEntries.add(new Entry(i, val));
}
final LineDataSet fadedDateSet = new LineDataSet(fadedEntries, "Faded");
fadedDateSet.setColor(0x42000000);

dataSets.add(fadedDateSet); // add the datasets

and launch the first item in the example app. Notice that the circles of DataSet1 is now semi-transparent, instead of solid black.

Solution:
This commit replaces mRenderPaint with null when drawing the circle bitmap. If a circleColor has been defined with a semi-transparent color, it will be drawn that way in the cached bitmap, hence the the bitmap itself does not need to be drawn with lower alpha.

ISSUE:
When using multiple LineDataSets like the follows:

    int solidColor = 0xFFFF00FF;
    dataSet.setColor(solidColor);
    dataSet.setCircleColor(solidColor);

    int semiTransparentColor = 0x8A000000;
    fadedSet.setColor(semiTransparentColor);

    LineData data = new LineData(dataSet, fadedSet);

the circles in 'dataSet' will rendered with the alpha from
fadedSet (0x8A).

The reason for this is that mRenderPaint is not reset properly
before drawing the circles. The first time drawCircles is called
the imageCache.fill(...) method is used where the color is set by
mRenderPaint.setColor(set.getCircleColor(i)), restoring the alpha
to 0xFF. The second time homever, imageCache.fill(...) is not called
which means that mRenderPaint will use it's old color/alpha,
which in this case is from fadedSet.

TEST INFO:
To trigger the issue, add the following to LineChartActivity1:

    final ArrayList<Entry> fadedEntries = new ArrayList<>();
    for (int i = 0; i < count; i++) {

        float val = (float) (Math.random() * range) + 3;
        fadedEntries.add(new Entry(i, val));
    }
    final LineDataSet fadedDateSet = new LineDataSet(fadedEntries, "Faded");
    fadedDateSet.setColor(0x42000000);

    dataSets.add(fadedDateSet); // add the datasets

and launch the first item in the example app.

SOLUTION:
This commit replaces mRenderPaint with null when drawing the circle
bitmap. If circleColor has been defined with a semi-transparent
color, it will be drawn that way in the cached bitmap, hence the the
bitmap itself does not need to be drawn with an alpha.
@patrick-elmquist patrick-elmquist changed the title Fix circles inherit alpha (Fixes #2620) Fix circles inherit alpha #2620 Jan 2, 2017
@danielgindi
Copy link
Collaborator

Thanks!

@danielgindi danielgindi merged commit 31b6022 into PhilJay:master Feb 21, 2017
regas99 pushed a commit to regas99/MPAndroidChart that referenced this pull request Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants