@@ -212,17 +212,14 @@ private XYItemSelection getMinMaxClosestSelection(ChartItem item, int viewX,
212212 if (bounds .isEmpty ()) return null ;
213213
214214 int [][] visibleBounds = contx .getVisibleBounds (bounds );
215- if (visibleBounds [0 ][0 ] == -1 && visibleBounds [0 ][1 ] == -1 &&
216- visibleBounds [1 ][0 ] == -1 && visibleBounds [1 ][1 ] == -1 )
217- return null ;
218-
215+ if (visibleBounds [0 ][0 ] == -1 && visibleBounds [0 ][1 ] == -1 ) return null ;
216+ else if (visibleBounds [1 ][0 ] == -1 && visibleBounds [1 ][1 ] == -1 ) return null ;
217+
219218 int firstVisible = visibleBounds [0 ][0 ];
220219 if (firstVisible == -1 ) firstVisible = visibleBounds [0 ][1 ];
221- if (firstVisible == -1 ) firstVisible = 0 ;
222-
220+
223221 int lastVisible = visibleBounds [1 ][0 ];
224222 if (lastVisible == -1 ) lastVisible = visibleBounds [1 ][1 ];
225- if (lastVisible == -1 ) lastVisible = xyItem .getValuesCount () - 1 ;
226223
227224 int idx = firstVisible ;
228225 int x = getViewX (contx , xyItem , idx );
@@ -315,33 +312,35 @@ private int[][] getMinMaxPoints(XYItem item, Rectangle dirtyArea,
315312
316313 if (dirtyArea .isEmpty ()) return null ;
317314
318- dirtyArea .grow (lineWidth , lineWidth );
315+ dirtyArea .grow (lineWidth , 0 );
316+
319317 int [][] visibleBounds = context .getVisibleBounds (dirtyArea );
320- if (visibleBounds [0 ][0 ] == -1 && visibleBounds [0 ][1 ] == -1 &&
321- visibleBounds [1 ][0 ] == -1 && visibleBounds [1 ][1 ] == -1 )
322- return null ;
318+ if (visibleBounds [0 ][0 ] == -1 && visibleBounds [0 ][1 ] == -1 ) return null ;
319+ else if (visibleBounds [1 ][0 ] == -1 && visibleBounds [1 ][1 ] == -1 ) return null ;
320+
321+ int valuesCount = item .getValuesCount ();
323322
324323 int firstIndex = visibleBounds [0 ][0 ];
325324 if (firstIndex == -1 ) firstIndex = visibleBounds [0 ][1 ];
326- if (firstIndex == - 1 ) firstIndex = 0 ;
325+ else if (firstIndex > 0 ) firstIndex --; // must use previous point to draw first line
327326
328- int valuesCount = item .getValuesCount ();
329327 int lastIndex = visibleBounds [1 ][0 ];
330328 if (lastIndex == -1 ) lastIndex = visibleBounds [1 ][1 ];
331- if (lastIndex == -1 ) lastIndex = valuesCount - 1 ;
332-
333- int firstX = getViewX (context , item , firstIndex );
334- while (firstIndex > 0 && getViewX (context , item , firstIndex ) >= firstX - lineWidth )
335- firstIndex --;
329+ else if (lastIndex < valuesCount - 1 ) lastIndex ++; // must use next point to draw last line
336330
337- int lastX = getViewX (context , item , lastIndex );
338- while (lastIndex < valuesCount - 1 && getViewX (context , item , lastIndex ) <= lastX + lineWidth )
339- lastIndex ++;
331+ // int firstX = getViewX(context, item, firstIndex);
332+ // while (firstIndex > 0 && getViewX(context, item, firstIndex) >= firstX - lineWidth)
333+ // firstIndex--;
334+ //
335+ // int lastX = getViewX(context, item, lastIndex);
336+ // while (lastIndex < valuesCount - 1 && getViewX(context, item, lastIndex) <= lastX + lineWidth)
337+ // lastIndex++;
340338
341339 double itemValueFactor = type == TYPE_RELATIVE ? getItemValueFactor (context ,
342340 maxValueOffset , item .getBounds ().height ) : 0 ;
343341
344- int maxPoints = Math .min ((lineWidth + dirtyArea .width + lineWidth ) * 4 , lastIndex - firstIndex + 1 );
342+ // int maxPoints = Math.min((lineWidth + dirtyArea.width + lineWidth) * 4, lastIndex - firstIndex + 1);
343+ int maxPoints = Math .min (dirtyArea .width * 4 + 2 , lastIndex - firstIndex + 1 ); // +2 for the extra invisible first & last points
345344
346345 int [] xPoints = new int [maxPoints + 2 ];
347346 int [] yPoints = new int [maxPoints + 2 ];
0 commit comments