@@ -212,17 +212,14 @@ private XYItemSelection getMinMaxClosestSelection(ChartItem item, int viewX,
212
212
if (bounds .isEmpty ()) return null ;
213
213
214
214
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
+
219
218
int firstVisible = visibleBounds [0 ][0 ];
220
219
if (firstVisible == -1 ) firstVisible = visibleBounds [0 ][1 ];
221
- if (firstVisible == -1 ) firstVisible = 0 ;
222
-
220
+
223
221
int lastVisible = visibleBounds [1 ][0 ];
224
222
if (lastVisible == -1 ) lastVisible = visibleBounds [1 ][1 ];
225
- if (lastVisible == -1 ) lastVisible = xyItem .getValuesCount () - 1 ;
226
223
227
224
int idx = firstVisible ;
228
225
int x = getViewX (contx , xyItem , idx );
@@ -315,33 +312,35 @@ private int[][] getMinMaxPoints(XYItem item, Rectangle dirtyArea,
315
312
316
313
if (dirtyArea .isEmpty ()) return null ;
317
314
318
- dirtyArea .grow (lineWidth , lineWidth );
315
+ dirtyArea .grow (lineWidth , 0 );
316
+
319
317
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 ();
323
322
324
323
int firstIndex = visibleBounds [0 ][0 ];
325
324
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
327
326
328
- int valuesCount = item .getValuesCount ();
329
327
int lastIndex = visibleBounds [1 ][0 ];
330
328
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
336
330
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++;
340
338
341
339
double itemValueFactor = type == TYPE_RELATIVE ? getItemValueFactor (context ,
342
340
maxValueOffset , item .getBounds ().height ) : 0 ;
343
341
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
345
344
346
345
int [] xPoints = new int [maxPoints + 2 ];
347
346
int [] yPoints = new int [maxPoints + 2 ];
0 commit comments