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

Highlight axis #4477

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Highlight axis #4477

wants to merge 23 commits into from

Conversation

regas99
Copy link

@regas99 regas99 commented Apr 2, 2019

PR Checklist:

  • [X ] I have tested this extensively and it does not break any existing behavior.
  • [ X] I have added/updated examples and tests for any new behavior.
  • [X ] If this is a significant change, an issue has already been created where the
    problem / solution was discussed: Display highlited Entry values on the axis #222

This PR adds support for axis highlighting as requested in issue #222 - Display highlited
Entry values on the axis.

It also fixes:
#3879 How to show x and y at XAxis and YAxis
#3550 Two markers
#3547 Get Highlight X position
#3269 How to add value of X label
#3669 Highlight xAxis.label background
#3484 How can I draw custom marker on highlighted entry in line chart

It provides a working example of custom axis formatting as discussed
in #2768 and #2801. Specifically, the right axis in HighlightMapActivity
uses a log log scale. It also has an interface - ICodecFormatter for axis
formatters that encode / decode values.

The PR incorporates my earlier PR #4550 because it builds on that prior work.

Updated wiki page:
Highlighting.zip

Screen shot:
screenshot

regas99 added 23 commits March 8, 2019 17:24
In BubbleChartHighlightActivity, click on the bubbles. Some clicks
work properly (highlight the bubble that was clicked), some clicks
highlight the wrong bubble, and some clicks do nothing.

I also refactored MainActivity. Previously it was painful to add
a new activity, especially if it is not at the bottom of the list.
The new implementation is cleaner - WISYWIG and easier to maintain.
Added mDrawnXRadius and mDrawnYRadius to BubbleEntry.
For details, see the BubbleEntry javadoc for these fields.
These are set / unset by BubbleChartRenderer when the chart is rendered.

BubbleEntry#containsX(xValue) and containsY(yValue) return true
if the entry contains the given value.
The y search was improperly setting closestYValue in the search loop,
sometimes causing the wrong entry to be found.

The warning about (closest != -1) never being false was bugging me.
It is gone now - the code and the warning.
Uses the Bubble Entry containsX() method to find all entries
containing x.
Bubbles are now properly de-highlighted when the same bubble is
touched two times in a row.
But keep new MainActivity.
saveTouchStart no longer runs a search through the data unless there
is at least one inverted axis on the chart.

Previously, saveTouchStart found the nearest entry and saved the data
set that the entry belonged to (as mClosestDataSetToTouch). In some
subsequent operations, e.g. drag, the data set was checked to see
if its axis is inverted.

If there is no inverted axis on the chart, we know a priori that
the check will always be negative. We skip the search in this case.

mClosestDataSetToTouch is replaced with mIsInverted. This does not
change the function, but makes the code much more readable.
Not all charts have an axis; some have x, left and right axes.
Axis information can be extracted from the chart type - if you
understand the taxonomy of the chart class / subclasses.
This change lets the subclass tell you what axes it has, and makes
those axes easily obtainable.

Be sure to call hasAxis before calling getAxis, or you may get a
run time error.
A highlight has x and y coordinates. When it is processed, e.g. drawn,
the element associated with the highlight is found by doing a search
through the data values. This search happens repeatedly whenever a
touch event occurs.

This commit uses the Highlight mDataIndex field to remember which
entry the highlight was generated from. Therefore we no longer
need to perform repeated searches.
Highlight now has a Type indicating the source of the highlight,
data value, x axis, left axis right axis or null. The NULL type is
intended to replace a null highlight, ala Kotlin.

Highlights is a collection of Highlight's which avoids
the use of an array (which is hardwired into the legacy
Highlight implementation).
If axis highlighting is enabled, an axis label
is drawn at the highlight point. The label
consists of an enclosing rectangle overlaid with
the axis value.

The fill color and padding, and the text color
are customizable.
deprecate drawHighlighted(Canvas c, Highlight[] indices),
replace with drawHighlights(Canvas c, Highlights highlights).
Methods that use Highlight[] should still work, but are deprecated.

Added methods to clear highlights in ChartInterface:
clearValueHighlights and clearAllHighlights.
When an axis is selected, the listener can callback to the activity
via the onAxisSelected and onNothingSelected methods.

To enable callbacks, the activity must implement
OnChartAxisSelectedListener and the dataset setHighlightEnabled
must be true.

OnChartAxisSelectedListener was created as a separate class so as to
not break existing code that uses OnChartValueSelectedListener.
ColorBubbleEntry is a BubbleEntry where each entry has its own color
(versus one color per data set in BubbleEntry). This provides more
control over rendering the bubbles.
Add Legend.setCustom(int[] colors, String[] labels)
This method is documented in the wiki, but does not exist.
Now it does.

Make Axis mAxisMaximum and mAxisMinimum protected,
as is says that should be in the java doc. I
will not be burned again!

Add a method to set the label color. This allows you to
make the default labels invisible (white) ands only
render the highlighted label.
Creates packages for chart example - classes were getting crowded.

This is a map of the largest cities in California. The right axis
is a log log scale of city population. Touching it does the following:

First touch - draw limit lines at +/- 20% of the touch population.
Display only cities whose population is between those values.

Second touch - draw limits lines at the first and second touch
points. Display only cities whose population is between those values.

Third touch - remove all highlights, reset to initial state.
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.

1 participant