Highlight axis by regas99 · Pull Request #4477 · PhilJay/MPAndroidChart
added 23 commits
March 8, 2019 17:24In 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.
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.
This was referenced
Apr 2, 2019This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters