1
1
/*
2
- * Copyright (c) 2007, 2011 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2007, 2019 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -337,7 +337,7 @@ private int[][] getMinMaxPoints(XYItem item, Rectangle dirtyArea,
337
337
double itemValueFactor = type == TYPE_RELATIVE ? getItemValueFactor (context ,
338
338
maxValueOffset , item .getBounds ().height ) : 0 ;
339
339
340
- int maxPoints = Math .max (dirtyArea .width , ( lastIndex - firstIndex + 1 ) * 3 );
340
+ int maxPoints = Math .min (dirtyArea .width * 4 , lastIndex - firstIndex + 1 );
341
341
342
342
int [] xPoints = new int [maxPoints + 2 ];
343
343
int [] yPoints = new int [maxPoints + 2 ];
@@ -348,46 +348,149 @@ private int[][] getMinMaxPoints(XYItem item, Rectangle dirtyArea,
348
348
int y = Utils .checkedInt (Math .ceil (getYValue (item , index ,
349
349
type , context , itemValueFactor )));
350
350
351
- if (nPoints == 0 ) { // First point
352
- xPoints [nPoints ] = x ;
353
- yPoints [nPoints ] = y ;
354
- nPoints ++;
355
- } else { // Other than first point
356
- int x_1 = xPoints [nPoints - 1 ];
351
+ int nValues = 0 ;
352
+
353
+ if (nPoints > 0 ) {
354
+ if (xPoints [nPoints - 1 ] == x ) nValues = 1 ;
357
355
358
- if (x_1 != x ) { // New point
359
- xPoints [nPoints ] = x ;
360
- yPoints [nPoints ] = y ;
361
- nPoints ++;
362
- } else { // Existing point
363
- int y_1 = yPoints [nPoints - 1 ];
356
+ if (nPoints > 1 ) {
357
+ if (xPoints [nPoints - 2 ] == x ) nValues = 2 ;
364
358
365
- if (nPoints > 1 && xPoints [nPoints - 2 ] == x_1 ) { // Existing point with two values
366
- int y_2 = yPoints [nPoints - 2 ];
367
-
368
- int minY = Math .min (y , y_1 );
369
- int maxY = Math .max (y , y_2 );
359
+ if (nPoints > 2 ) {
360
+ if (xPoints [nPoints - 3 ] == x ) nValues = 3 ;
370
361
371
- yPoints [nPoints - 3 ] = minY ;
372
- yPoints [nPoints - 2 ] = maxY ;
373
- yPoints [nPoints - 1 ] = minY ;
374
- } else { // Existing point with one value
375
- if (y_1 != y ) { // Creating second value
376
- int minY = Math .min (y , y_1 );
377
- int maxY = Math .max (y , y_1 );
378
-
379
- yPoints [nPoints - 1 ] = minY ;
380
-
362
+ if (nPoints > 3 ) {
363
+ if (xPoints [nPoints - 4 ] == x ) nValues = 4 ;
364
+ }
365
+ }
366
+ }
367
+ }
368
+
369
+ switch (nValues ) {
370
+ // New point at X
371
+ case 0 :
372
+ if (nPoints < 2 || yPoints [nPoints - 1 ] != y || yPoints [nPoints - 2 ] != y ) { // first, second or new point, create it
373
+ xPoints [nPoints ] = x ;
374
+ yPoints [nPoints ] = y ;
375
+ nPoints ++;
376
+ } else { // repeated point, collapse it
377
+ xPoints [nPoints - 1 ] = x ;
378
+ }
379
+
380
+ break ;
381
+
382
+ // Second point at X
383
+ case 1 :
384
+ if (yPoints [nPoints - 1 ] != y ) { // only add second point if its value differs from the first point
385
+ xPoints [nPoints ] = x ;
386
+ yPoints [nPoints ] = y ;
387
+ nPoints ++;
388
+ }
389
+
390
+ break ;
391
+
392
+ // Third point at X
393
+ case 2 :
394
+ int y_1_2 = yPoints [nPoints - 1 ];
395
+ if (y_1_2 != y ) { // only add third point if its value differs from the second point
396
+ if (yPoints [nPoints - 2 ] < y_1_2 && y_1_2 < y ) { // new maximum value, collapse it
397
+ yPoints [nPoints - 1 ] = y ;
398
+ } else if (yPoints [nPoints - 2 ] > y_1_2 && y_1_2 > y ) { // new minimum value, collapse it
399
+ yPoints [nPoints - 1 ] = y ;
400
+ } else { // new end value, create it
381
401
xPoints [nPoints ] = x ;
382
- yPoints [nPoints ] = maxY ;
402
+ yPoints [nPoints ] = y ;
383
403
nPoints ++;
384
-
404
+ }
405
+ }
406
+
407
+ break ;
408
+
409
+ // Fourth point at X
410
+ case 3 :
411
+ int y_1_3 = yPoints [nPoints - 1 ];
412
+ if (y_1_3 != y ) { // only add fourth point if its value differs from the third point
413
+ int y_2_3 = yPoints [nPoints - 2 ];
414
+ int y_3_3 = yPoints [nPoints - 3 ];
415
+
416
+ int min = y ;
417
+ int max = y ;
418
+
419
+ if (y_1_3 < min ) min = y_1_3 ;
420
+ else if (y_1_3 > max ) max = y_1_3 ;
421
+
422
+ if (y_2_3 < min ) min = y_2_3 ;
423
+ else if (y_2_3 > max ) max = y_2_3 ;
424
+
425
+ if (y_3_3 < min ) min = y_3_3 ;
426
+ else if (y_3_3 > max ) max = y_3_3 ;
427
+
428
+ if (y == min ) {
429
+ if (y_3_3 == max ) {
430
+ yPoints [nPoints - 2 ] = y ;
431
+ nPoints --;
432
+ } else {
433
+ yPoints [nPoints - 2 ] = max ;
434
+ yPoints [nPoints - 1 ] = y ;
435
+ }
436
+ } else if (y == max ) {
437
+ if (y_3_3 == min ) {
438
+ yPoints [nPoints - 2 ] = y ;
439
+ nPoints --;
440
+ } else {
441
+ yPoints [nPoints - 2 ] = min ;
442
+ yPoints [nPoints - 1 ] = y ;
443
+ }
444
+ } else if (y_3_3 == min ) {
445
+ yPoints [nPoints - 2 ] = max ;
446
+ yPoints [nPoints - 1 ] = y ;
447
+ } else if (y_3_3 == max ) {
448
+ yPoints [nPoints - 2 ] = min ;
449
+ yPoints [nPoints - 1 ] = y ;
450
+ } else {
385
451
xPoints [nPoints ] = x ;
386
- yPoints [nPoints ] = minY ;
452
+ yPoints [nPoints ] = y ;
387
453
nPoints ++;
388
454
}
389
455
}
390
- }
456
+
457
+ break ;
458
+
459
+ // Another point at X
460
+ case 4 :
461
+ int y_1_4 = yPoints [nPoints - 1 ];
462
+ if (y_1_4 != y ) { // only add another point if its value differs from the fourth point
463
+ int y_2_4 = yPoints [nPoints - 2 ];
464
+ int y_3_4 = yPoints [nPoints - 3 ];
465
+ int y_4_4 = yPoints [nPoints - 4 ];
466
+
467
+ int min = y ;
468
+ int max = y ;
469
+
470
+ if (y_1_4 < min ) min = y_1_4 ;
471
+ else if (y_1_4 > max ) max = y_1_4 ;
472
+
473
+ if (y_2_4 < min ) min = y_2_4 ;
474
+ else if (y_2_4 > max ) max = y_2_4 ;
475
+
476
+ if (y_3_4 < min ) min = y_3_4 ;
477
+ else if (y_3_4 > max ) max = y_3_4 ;
478
+
479
+ if (y_4_4 < min ) min = y_4_4 ;
480
+ else if (y_4_4 > max ) max = y_4_4 ;
481
+
482
+ if (y == min ) {
483
+ yPoints [nPoints - 3 ] = max ;
484
+ yPoints [nPoints - 2 ] = y ;
485
+ nPoints --;
486
+ } else if (y == max ) {
487
+ yPoints [nPoints - 3 ] = min ;
488
+ yPoints [nPoints - 2 ] = y ;
489
+ nPoints --;
490
+ } else {
491
+ yPoints [nPoints - 1 ] = y ;
492
+ }
493
+ }
391
494
}
392
495
}
393
496
0 commit comments