-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathChartUtils.java
More file actions
854 lines (755 loc) · 36.7 KB
/
ChartUtils.java
File metadata and controls
854 lines (755 loc) · 36.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
import java.awt.Color;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import com.jogamp.opengl.GL2;
public class ChartUtils {
/**
* Determines the best y values to use for vertical divisions. The 1/2/5 pattern is used (1,2,5,10,20,50,100,200,500...)
*
* @param plotHeight Number of pixels for the y-axis
* @param minY Y value at the bottom of the plot
* @param maxY Y value at the top of the plot
* @return A Map of the y values for each division, keys are Floats and values are formatted Strings
*/
public static Map<Float, String> getYdivisions125(float plotHeight, float minY, float maxY) {
// calculate the best vertical division size
float minSpacingBetweenText = 2.0f * FontUtils.tickTextHeight;
float maxDivisionsCount = plotHeight / (FontUtils.tickTextHeight + minSpacingBetweenText) + 1.0f;
float divisionSize = (maxY - minY) / maxDivisionsCount;
float closestDivSize1 = (float) Math.pow(10.0, Math.ceil(Math.log10(divisionSize/1.0))) * 1.0f; // closest (10^n)*1 that is >= divisionSize, such as 1,10,100,1000
float closestDivSize2 = (float) Math.pow(10.0, Math.ceil(Math.log10(divisionSize/2.0))) * 2.0f; // closest (10^n)*2 that is >= divisionSize, such as 2,20,200,2000
float closestDivSize5 = (float) Math.pow(10.0, Math.ceil(Math.log10(divisionSize/5.0))) * 5.0f; // closest (10^n)*5 that is >= divisionSize, such as 5,50,500,5000
float error1 = closestDivSize1 - divisionSize;
float error2 = closestDivSize2 - divisionSize;
float error5 = closestDivSize5 - divisionSize;
if(error1 < error2 && error1 < error5)
divisionSize = closestDivSize1;
else if(error2 < error1 && error2 < error5)
divisionSize = closestDivSize2;
else
divisionSize = closestDivSize5;
// decide if the numbers should be displayed as integers, or as floats to one significant decimal place
int precision = 0;
String format = "";
if(divisionSize < 0.99) {
precision = 1;
float size = divisionSize;
while(size * (float) Math.pow(10, precision) < 1.0f)
precision++;
format = "%." + precision + "f";
}
// calculate the values for each vertical division
float firstDivision = maxY - (maxY % divisionSize);
float lastDivision = minY - (minY % divisionSize);
if(firstDivision > maxY)
firstDivision -= divisionSize;
if(lastDivision < minY)
lastDivision += divisionSize;
int divisionCount = (int) Math.round((firstDivision - lastDivision) / divisionSize) + 1;
Map<Float, String> yValues = new HashMap<Float, String>();
for(int i = 0; i < divisionCount; i++) {
float number = firstDivision - (i * divisionSize);
String text;
if(precision == 0) {
text = Integer.toString((int) number);
} else {
text = String.format(format, number);
}
yValues.put(number, text);
}
return yValues;
}
/**
* Determines the best Log10 y values to use for vertical divisions. Division size will be either 1e1, 1e3 or 1e9.
*
* @param plotHeight Number of pixels for the y-axis
* @param minY Y value at the bottom of the plot
* @param maxY Y value at the top of the plot
* @return A Map of the y values for each division, keys are Floats and values are formatted Strings
*/
public static Map<Float, String> getLogYdivisions(float plotHeight, float minY, float maxY) {
// calculate the best vertical division size
float minSpacingBetweenText = 2.0f * FontUtils.tickTextHeight;
float maxDivisionsCount = plotHeight / (FontUtils.tickTextHeight + minSpacingBetweenText) + 1.0f;
float divisionSize = (maxY - minY) / maxDivisionsCount;
float divSize1 = 1.0f; // 1W, 100mW, 10mW, 1mW, 100uW, ...
float divSize3 = 3.0f; // 1W, 1mW, 1uW, ...
float divSize9 = 9.0f; // 1W, 1nW, ...
float error1 = divSize1 - divisionSize;
float error3 = divSize3 - divisionSize;
float error9 = divSize9 - divisionSize;
if(error1 > 0 && error1 < error3 && error1 < error9)
divisionSize = divSize1;
else if(error3 > 0 && error3 < error9)
divisionSize = divSize3;
else if(error9 > 0)
divisionSize = divSize9;
else
return new HashMap<Float, String>();
// calculate the values for each vertical division
float firstDivision = maxY - (maxY % divisionSize);
float lastDivision = minY - (minY % divisionSize);
if(firstDivision > maxY)
firstDivision -= divisionSize;
if(lastDivision < minY)
lastDivision += divisionSize;
int divisionCount = (int) Math.round((firstDivision - lastDivision) / divisionSize) + 1;
// if(divisionCount > Math.floor(maxDivisionsCount))
// divisionCount = (int) Math.floor(maxDivisionsCount);
Map<Float, String> yValues = new HashMap<Float, String>();
for(int i = 0; i < divisionCount; i++) {
float number = firstDivision - (i * divisionSize);
String text = "1e" + Integer.toString((int) number);
yValues.put(number, text);
}
return yValues;
}
/**
* Determines the best integer x values to use for horizontal divisions. The 1/2/5 pattern is used (1,2,5,10,20,50,100,200,500...)
*
* @param plotWidth Number of pixels for the x-axis
* @param minX X value at the left of the plot
* @param maxX X value at the right of the plot
* @return A Map of the x values for each division, keys are Integers and values are formatted Strings
*/
public static Map<Integer, String> getXdivisions125(float plotWidth, int minX, int maxX) {
// calculate the best horizontal division size
int textWidth = (int) Float.max(FontUtils.tickTextWidth(Integer.toString(maxX)), FontUtils.tickTextWidth(Integer.toString(minX)));
int minSpacingBetweenText = textWidth;
float maxDivisionsCount = plotWidth / (textWidth + minSpacingBetweenText);
int divisionSize = (int) Math.ceil((maxX - minX) / maxDivisionsCount);
if(divisionSize == 0) divisionSize = 1;
int closestDivSize1 = (int) Math.pow(10.0, Math.ceil(Math.log10(divisionSize/1.0))) * 1; // closest (10^n)*1 that is >= divisionSize, such as 1,10,100,1000
int closestDivSize2 = (int) Math.pow(10.0, Math.ceil(Math.log10(divisionSize/2.0))) * 2; // closest (10^n)*2 that is >= divisionSize, such as 2,20,200,2000
int closestDivSize5 = (int) Math.pow(10.0, Math.ceil(Math.log10(divisionSize/5.0))) * 5; // closest (10^n)*5 that is >= divisionSize, such as 5,50,500,5000
int error1 = closestDivSize1 - divisionSize;
int error2 = closestDivSize2 - divisionSize;
int error5 = closestDivSize5 - divisionSize;
if(error1 < error2 && error1 < error5)
divisionSize = closestDivSize1;
else if(error2 < error1 && error2 < error5)
divisionSize = closestDivSize2;
else
divisionSize= closestDivSize5;
// calculate the values for each horizontal division
int firstDivision = maxX - (maxX % divisionSize);
int lastDivision = minX - (minX % divisionSize);
if(firstDivision > maxX)
firstDivision -= divisionSize;
if(lastDivision < minX)
lastDivision += divisionSize;
int divisionCount = ((firstDivision - lastDivision) / divisionSize + 1);
Map<Integer, String> xValues = new HashMap<Integer, String>();
for(int i = 0; i < divisionCount; i++) {
int number = lastDivision + (i * divisionSize);
String text = Integer.toString(number);
xValues.put(number, text);
}
return xValues;
}
/**
* Determines the best floating point x values to use for horizontal divisions. The 1/2/5 pattern is used (.1,.2,.5,1,2,5,10,20,50...)
*
* @param plotWidth Number of pixels for the x-axis
* @param minX X value at the left of the plot
* @param maxX X value at the right of the plot
* @return A Map of the x values for each division, keys are Integers and values are formatted Strings
*/
public static Map<Float, String> getFloatXdivisions125(float plotWidth, float minX, float maxX) {
Map<Float, String> xValues = new HashMap<Float, String>();
for(int maxDivisionsCount = 1; maxDivisionsCount < 100; maxDivisionsCount++) {
float divisionSize = (maxX - minX) / (float) maxDivisionsCount;
float closestDivSize1 = (float) Math.pow(10.0, Math.ceil(Math.log10(divisionSize/1.0))) * 1; // closest (10^n)*1 that is >= divisionSize, such as 1,10,100,1000
float closestDivSize2 = (float) Math.pow(10.0, Math.ceil(Math.log10(divisionSize/2.0))) * 2; // closest (10^n)*2 that is >= divisionSize, such as 2,20,200,2000
float closestDivSize5 = (float) Math.pow(10.0, Math.ceil(Math.log10(divisionSize/5.0))) * 5; // closest (10^n)*5 that is >= divisionSize, such as 5,50,500,5000
float error1 = closestDivSize1 - divisionSize;
float error2 = closestDivSize2 - divisionSize;
float error5 = closestDivSize5 - divisionSize;
if(error1 < error2 && error1 < error5)
divisionSize = closestDivSize1;
else if(error2 < error1 && error2 < error5)
divisionSize = closestDivSize2;
else
divisionSize= closestDivSize5;
// decide if the numbers should be displayed as integers, or as floats to one significant decimal place
int precision = 0;
String format = "";
if(divisionSize < 0.99) {
precision = 1;
float size = divisionSize;
while(size * (float) Math.pow(10, precision) < 1.0f)
precision++;
format = "%." + precision + "f";
}
// calculate the values for each vertical division
float firstDivision = maxX - (maxX % divisionSize);
float lastDivision = minX - (minX % divisionSize);
firstDivision += divisionSize; // compensating for floating point error that may skip the end points
lastDivision -= divisionSize;
while(firstDivision > maxX)
firstDivision -= divisionSize;
while(lastDivision < minX)
lastDivision += divisionSize;
int divisionCount = (int) Math.round((firstDivision - lastDivision) / divisionSize) + 1;
Map<Float, String> proposedXvalues = new HashMap<Float, String>();
for(int i = 0; i < divisionCount; i++) {
float number = firstDivision - (i * divisionSize);
String text;
if(precision == 0) {
text = Integer.toString((int) number);
} else {
text = String.format(format, number);
}
proposedXvalues.put(number, text);
}
// calculate how much width is taken up by the text
float width = 0;
for(String s : proposedXvalues.values())
width += FontUtils.tickTextWidth(s);
// stop and don't use this iteration if we're using more than half of the width
if(width > plotWidth / 2.0f)
break;
xValues = proposedXvalues;
}
return xValues;
}
/**
* Formats a double as a string, limiting the total number of digits to a specific length, but never truncating the integer part.
*
* For example, with a digitCount of 4:
* 1.234567 -> "1.234"
* 12.34567 -> "12.34"
* 123456.7 -> "123456"
* -1.23456 -> "-1.234"
*
* @param number The double to format.
* @param digitCount How many digits to clip to.
* @return The double formatted as a String.
*/
public static String formattedNumber(double number, int digitCount) {
String text = String.format("%.9f", number);
int pointLocation = text.indexOf('.');
int stringLength = text.charAt(0) == '-' ? digitCount + 2 : digitCount + 1;
if(text.length() > (pointLocation < stringLength ? stringLength : pointLocation)){
return text.substring(0, pointLocation < stringLength ? stringLength : pointLocation);
} else {
return text.substring(1, text.length());
}
}
/**
* Takes a string of text and attempts to parse it with a format string.
* Throws an exception if the text does not match the format string, or if the format string is invalid.
*
* @param line Line number to show in the error message if an error occurs.
* @param text Line of text to parse.
* @param formatString Printf-style format string but with many limitations:
* 1. Only %d %f %s or %b (boolean) can be used.
2. A %d or %f can only be at the very beginning or very end. A %s or %b can only be at the very end.
3. There must be a space between %d/%f/%s/%b and the rest of the text.
* @return An Integer if %d was used, a Float if %f was used, a String if %s was used, a Boolean if %b was used, or null if no format specifier was used.
*/
public static Object parse(int line, String text, String formatString) {
// error message line numbers should start at 1 but the argument starts at 0
line++;
// no format specifier, so just ensure the text matches the formatString exactly
if(!formatString.contains("%")) {
if(text.equals(formatString))
return null;
else
throw new AssertionError("Line " + line + ": Text does not match the expected value.");
}
// starting with %d, so an integer should be at the start of the text
if(formatString.startsWith("%d")) {
try {
String[] tokens = text.split(" ");
int number = Integer.parseInt(tokens[0]);
String expectedText = formatString.substring(2);
String remainingText = "";
for(int i = 1; i < tokens.length; i++)
remainingText += " " + tokens[i];
if(remainingText.equals(expectedText))
return number;
else
throw new AssertionError("Line " + line + ": Text does not match the expected value.");
} catch(Exception e) {
throw new AssertionError("Line " + line + ": Text does not start with an integer.");
}
}
// starting with %f, so a float should be at the start of the text
if(formatString.startsWith("%f")) {
try {
String[] tokens = text.split(" ");
float number = Float.parseFloat(tokens[0]);
String expectedText = formatString.substring(2);
String remainingText = "";
for(int i = 1; i < tokens.length; i++)
remainingText += " " + tokens[i];
if(remainingText.equals(expectedText))
return number;
else
throw new AssertionError("Line " + line + ": Text does not match the expected value.");
} catch(Exception e) {
throw new AssertionError("Line " + line + ": Text does not start with a floating point number.");
}
}
// ending with %d, so an integer should be at the end of the text
if(formatString.endsWith("%d")) {
try {
String[] tokens = text.split(" ");
int number = Integer.parseInt(tokens[tokens.length - 1]);
String expectedText = formatString.substring(0, formatString.length() - 2);
String remainingText = "";
for(int i = 0; i < tokens.length - 1; i++)
remainingText += tokens[i] + " ";
if(remainingText.equals(expectedText))
return number;
else
throw new AssertionError("Line " + line + ": Text does not match the expected value.");
} catch(Exception e) {
throw new AssertionError("Line " + line + ": Text does not end with an integer.");
}
}
// ending with %f, so a float should be at the end of the text
if(formatString.endsWith("%f")) {
try {
String[] tokens = text.split(" ");
float number = Float.parseFloat(tokens[tokens.length - 1]);
String expectedText = formatString.substring(0, formatString.length() - 2);
String remainingText = "";
for(int i = 0; i < tokens.length - 1; i++)
remainingText += tokens[i] + " ";
if(remainingText.equals(expectedText))
return number;
else
throw new AssertionError("Line " + line + ": Text does not match the expected value.");
} catch(Exception e) {
throw new AssertionError("Line " + line + ": Text does not end with a floating point number.");
}
}
// ending with %s, so a String should be at the end of the text
if(formatString.endsWith("%s")) {
try {
String expectedText = formatString.substring(0, formatString.length() - 2);
String actualText = text.substring(0, expectedText.length());
String token = text.substring(expectedText.length());
if(actualText.equals(expectedText))
return token;
else
throw new AssertionError("Line " + line + ": Text does not match the expected value.");
} catch(Exception e) {
throw new AssertionError("Line " + line + ": Text does not match the expected value.");
}
}
// ending with %b, so a Boolean should be at the end of the text
if(formatString.endsWith("%b")) {
try {
String expectedText = formatString.substring(0, formatString.length() - 2);
String actualText = text.substring(0, expectedText.length());
String token = text.substring(expectedText.length());
if(actualText.equals(expectedText))
return Boolean.parseBoolean(token);
else
throw new AssertionError("Line " + line + ": Text does not match the expected value.");
} catch(Exception e) {
throw new AssertionError("Line " + line + ": Text does not match the expected value.");
}
}
// formatString is not as expected
throw new AssertionError("Line " + line + ": Source code contains an invalid format string.");
}
/**
* Parses an ASCII STL file to extract it's vertices and normal vectors.
*
* Blender users: when exporting the STL file (File > Export > Stl) ensure the "Ascii" checkbox is selected,
* and ensure your model fits in a bounding box from -1 to +1 Blender units, centered at the origin.
*
* @param fileStream InputStream of an ASCII STL file.
* @returns A float[] with a layout of u,v,w,x1,y1,z1,x2,y2,z2,x3,y3,z3 ... or null if the InputStream could not be parsed.
*/
public static float[] getShapeFromAsciiStl(InputStream fileStream) {
try {
// get the lines of text
List<String> lines = new ArrayList<String>();
Scanner s = new Scanner(fileStream);
while(s.hasNextLine())
lines.add(s.nextLine());
s.close();
// count the vertices
int vertexCount = 0;
for(String line : lines)
if(line.startsWith("facet normal") || line.startsWith("vertex"))
vertexCount += 3;
// copy the vertices into the float[]
float[] shape = new float[vertexCount];
int vertex = 0;
for(String line : lines) {
if(line.startsWith("facet normal")) {
String[] token = line.split(" ");
shape[vertex++] = Float.parseFloat(token[2]);
shape[vertex++] = Float.parseFloat(token[3]);
shape[vertex++] = Float.parseFloat(token[4]);
} else if(line.startsWith("vertex")) {
String[] token = line.split(" ");
shape[vertex++] = Float.parseFloat(token[1]);
shape[vertex++] = Float.parseFloat(token[2]);
shape[vertex++] = Float.parseFloat(token[3]);
}
}
return shape;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Draws a tooltip. An anchor point specifies where the tooltip should point to.
*
* @param gl The OpenGL context.
* @param text Array of text to show.
* @param color Corresponding array of colors to show at the left of each line of text.
* @param anchorX X location to point to.
* @param anchorY Y location to point to.
* @param topLeftX Allowed bounding box's top-left x coordinate.
* @param topLeftY Allowed bounding box's top-left y coordinate.
* @param bottomRightX Allowed bounding box's bottom-right x coordinate.
* @param bottomRightY Allowed bounding box's bottom-right y coordinate.
*/
public static void drawTooltip(GL2 gl, String[] text, Color[] colors, int anchorX, int anchorY, float topLeftX, float topLeftY, float bottomRightX, float bottomRightY) {
final int NORTH = 0;
final int SOUTH = 1;
final int WEST = 2;
final int EAST = 3;
final int NORTH_WEST = 4;
final int NORTH_EAST = 5;
final int SOUTH_WEST = 6;
final int SOUTH_EAST = 7;
float padding = 6f * Controller.getDisplayScalingFactor();
float maxTextWidth = FontUtils.tickTextWidth(text[0]);
for(int i = 1; i < text.length; i++)
if(FontUtils.tickTextWidth(text[i]) > maxTextWidth)
maxTextWidth = FontUtils.tickTextWidth(text[i]);
float textHeight = FontUtils.tickTextHeight;
float boxWidth = textHeight + Theme.tooltipTextPadding + maxTextWidth + (2 * padding);
float boxHeight = text.length * (textHeight + padding) + padding;
// decide which orientation to draw the tooltip in, or return if there is not enough space
int orientation = NORTH;
if(anchorY + padding + boxHeight < topLeftY) {
// there is space above the anchor, so use NORTH or NORTH_WEST or NORTH_EAST if there is enough horizontal space
if(anchorX - (boxWidth / 2f) > topLeftX && anchorX + (boxWidth / 2f) < bottomRightX)
orientation = NORTH;
else if(anchorX - boxWidth > topLeftX && anchorX < bottomRightX)
orientation = NORTH_WEST;
else if(anchorX > topLeftX && anchorX + boxWidth < bottomRightX)
orientation = NORTH_EAST;
else
return;
} else if(anchorY + (boxHeight / 2f) < topLeftY && anchorY - (boxHeight / 2f) > bottomRightY) {
// there is some space above and below the anchor, so use WEST or EAST if there is enough horizontal space
if(anchorX - padding - boxWidth > topLeftX)
orientation = WEST;
else if(anchorX + padding + boxWidth < bottomRightX)
orientation = EAST;
else
return;
} else if(anchorY - padding - boxHeight > bottomRightY) {
// there is space below the anchor, so use SOUTH or SOUTH_WEST or SOUTH_EAST if there is enough horizontal space
if(anchorX - (boxWidth / 2f) > topLeftX && anchorX + (boxWidth / 2f) < bottomRightX)
orientation = SOUTH;
else if(anchorX - boxWidth > topLeftX && anchorX < bottomRightX)
orientation = SOUTH_WEST;
else if(anchorX > topLeftX && anchorX + boxWidth < bottomRightX)
orientation = SOUTH_EAST;
else
return;
} else {
// there is not enough space anywhere
return;
}
// draw the tooltip
if(orientation == NORTH) {
gl.glColor4fv(Theme.tooltipBackgroundColor, 0);
gl.glBegin(GL2.GL_TRIANGLES);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX + (padding / 2f), anchorY + padding);
gl.glVertex2f(anchorX - (padding / 2f), anchorY + padding);
gl.glEnd();
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f(anchorX - (boxWidth / 2f), anchorY + padding + boxHeight);
gl.glVertex2f(anchorX - (boxWidth / 2f), anchorY + padding);
gl.glVertex2f(anchorX + (boxWidth / 2f), anchorY + padding);
gl.glVertex2f(anchorX + (boxWidth / 2f), anchorY + padding + boxHeight);
gl.glEnd();
gl.glColor4fv(Theme.tooltipBorderColor, 0);
gl.glBegin(GL2.GL_LINE_LOOP);
gl.glVertex2f(anchorX - (boxWidth / 2f), anchorY + padding + boxHeight);
gl.glVertex2f(anchorX - (boxWidth / 2f), anchorY + padding);
gl.glVertex2f(anchorX - (padding / 2f), anchorY + padding);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX + (padding / 2f), anchorY + padding);
gl.glVertex2f(anchorX + (boxWidth / 2f), anchorY + padding);
gl.glVertex2f(anchorX + (boxWidth / 2f), anchorY + padding + boxHeight);
gl.glEnd();
// draw the text and color boxes
float textX = anchorX - (boxWidth / 2f) + padding + textHeight + Theme.tooltipTextPadding;
for(int i = 0; i < text.length; i++) {
float textY = anchorY + padding + boxHeight - ((i + 1) * (padding + textHeight));
FontUtils.drawTickText(text[i], (int) textX, (int) textY);
gl.glBegin(GL2.GL_QUADS);
gl.glColor4fv(new float[] {colors[i].getRed() / 255f, colors[i].getGreen() / 255f, colors[i].getBlue() / 255f, 1}, 0);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY + textHeight);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY + textHeight);
gl.glEnd();
}
} else if(orientation == SOUTH) {
gl.glColor4fv(Theme.tooltipBackgroundColor, 0);
gl.glBegin(GL2.GL_TRIANGLES);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX - (padding / 2f), anchorY - padding);
gl.glVertex2f(anchorX + (padding / 2f), anchorY - padding);
gl.glEnd();
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f(anchorX - (boxWidth / 2f), anchorY - padding);
gl.glVertex2f(anchorX - (boxWidth / 2f), anchorY - padding - boxHeight);
gl.glVertex2f(anchorX + (boxWidth / 2f), anchorY - padding - boxHeight);
gl.glVertex2f(anchorX + (boxWidth / 2f), anchorY - padding);
gl.glEnd();
gl.glColor4fv(Theme.tooltipBorderColor, 0);
gl.glBegin(GL2.GL_LINE_LOOP);
gl.glVertex2f(anchorX - (boxWidth / 2f), anchorY - padding);
gl.glVertex2f(anchorX - (boxWidth / 2f), anchorY - padding - boxHeight);
gl.glVertex2f(anchorX + (boxWidth / 2f), anchorY - padding - boxHeight);
gl.glVertex2f(anchorX + (boxWidth / 2f), anchorY - padding);
gl.glVertex2f(anchorX + (padding / 2f), anchorY - padding);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX - (padding / 2f), anchorY - padding);
gl.glEnd();
// draw the text and color boxes
float textX = anchorX - (boxWidth / 2f) + padding + textHeight + Theme.tooltipTextPadding;
for(int i = 0; i < text.length; i++) {
float textY = anchorY - padding - ((i + 1) * (padding + textHeight));
FontUtils.drawTickText(text[i], (int) textX, (int) textY);
gl.glBegin(GL2.GL_QUADS);
gl.glColor4fv(new float[] {colors[i].getRed() / 255f, colors[i].getGreen() / 255f, colors[i].getBlue() / 255f, 1}, 0);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY + textHeight);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY + textHeight);
gl.glEnd();
}
} else if(orientation == WEST) {
gl.glColor4fv(Theme.tooltipBackgroundColor, 0);
gl.glBegin(GL2.GL_TRIANGLES);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX - padding, anchorY + (padding / 2f));
gl.glVertex2f(anchorX - padding, anchorY - (padding / 2f));
gl.glEnd();
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f(anchorX - padding - boxWidth, anchorY + (boxHeight / 2f));
gl.glVertex2f(anchorX - padding - boxWidth, anchorY - (boxHeight / 2f));
gl.glVertex2f(anchorX - padding, anchorY - (boxHeight / 2f));
gl.glVertex2f(anchorX - padding, anchorY + (boxHeight / 2f));
gl.glEnd();
gl.glColor4fv(Theme.tooltipBorderColor, 0);
gl.glBegin(GL2.GL_LINE_LOOP);
gl.glVertex2f(anchorX - padding - boxWidth, anchorY + (boxHeight / 2f));
gl.glVertex2f(anchorX - padding - boxWidth, anchorY - (boxHeight / 2f));
gl.glVertex2f(anchorX - padding, anchorY - (boxHeight / 2f));
gl.glVertex2f(anchorX - padding, anchorY - (padding / 2f));
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX - padding, anchorY + (padding / 2f));
gl.glVertex2f(anchorX - padding, anchorY + (boxHeight / 2f));
gl.glEnd();
// draw the text and color boxes
float textX = anchorX - boxWidth + textHeight + Theme.tooltipTextPadding;
for(int i = 0; i < text.length; i++) {
float textY = anchorY + (boxHeight / 2f) - ((i + 1) * (padding + textHeight));
FontUtils.drawTickText(text[i], (int) textX, (int) textY);
gl.glBegin(GL2.GL_QUADS);
gl.glColor4fv(new float[] {colors[i].getRed() / 255f, colors[i].getGreen() / 255f, colors[i].getBlue() / 255f, 1}, 0);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY + textHeight);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY + textHeight);
gl.glEnd();
}
} else if(orientation == EAST) {
gl.glColor4fv(Theme.tooltipBackgroundColor, 0);
gl.glBegin(GL2.GL_TRIANGLES);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX + padding, anchorY - (padding / 2f));
gl.glVertex2f(anchorX + padding, anchorY + (padding / 2f));
gl.glEnd();
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f(anchorX + padding, anchorY + (boxHeight / 2f));
gl.glVertex2f(anchorX + padding, anchorY - (boxHeight / 2f));
gl.glVertex2f(anchorX + padding + boxWidth, anchorY - (boxHeight / 2f));
gl.glVertex2f(anchorX + padding + boxWidth, anchorY + (boxHeight / 2f));
gl.glEnd();
gl.glColor4fv(Theme.tooltipBorderColor, 0);
gl.glBegin(GL2.GL_LINE_LOOP);
gl.glVertex2f(anchorX + padding, anchorY + (boxHeight / 2f));
gl.glVertex2f(anchorX + padding, anchorY + (padding / 2f));
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX + padding, anchorY - (padding / 2f));
gl.glVertex2f(anchorX + padding, anchorY - (boxHeight / 2f));
gl.glVertex2f(anchorX + padding + boxWidth, anchorY - (boxHeight / 2f));
gl.glVertex2f(anchorX + padding + boxWidth, anchorY + (boxHeight / 2f));
gl.glEnd();
// draw the text and color boxes
float textX = anchorX + (2f * padding) + textHeight + Theme.tooltipTextPadding;
for(int i = 0; i < text.length; i++) {
float textY = anchorY + (boxHeight / 2f) - ((i + 1) * (padding + textHeight));
FontUtils.drawTickText(text[i], (int) textX, (int) textY);
gl.glBegin(GL2.GL_QUADS);
gl.glColor4fv(new float[] {colors[i].getRed() / 255f, colors[i].getGreen() / 255f, colors[i].getBlue() / 255f, 1}, 0);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY + textHeight);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY + textHeight);
gl.glEnd();
}
} else if(orientation == NORTH_WEST) {
gl.glColor4fv(Theme.tooltipBackgroundColor, 0);
gl.glBegin(GL2.GL_TRIANGLES);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX, anchorY + padding);
gl.glVertex2f(anchorX - (0.85f * padding), anchorY + padding);
gl.glEnd();
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f(anchorX - boxWidth, anchorY + padding + boxHeight);
gl.glVertex2f(anchorX - boxWidth, anchorY + padding);
gl.glVertex2f(anchorX, anchorY + padding);
gl.glVertex2f(anchorX, anchorY + padding + boxHeight);
gl.glEnd();
gl.glColor4fv(Theme.tooltipBorderColor, 0);
gl.glBegin(GL2.GL_LINE_LOOP);
gl.glVertex2f(anchorX - boxWidth, anchorY + padding + boxHeight);
gl.glVertex2f(anchorX - boxWidth, anchorY + padding);
gl.glVertex2f(anchorX - (0.85f * padding), anchorY + padding);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX, anchorY + padding + boxHeight);
gl.glEnd();
// draw the text and color boxes
float textX = anchorX - boxWidth + padding + textHeight + Theme.tooltipTextPadding;
for(int i = 0; i < text.length; i++) {
float textY = anchorY + padding + boxHeight - ((i + 1) * (padding + textHeight));
FontUtils.drawTickText(text[i], (int) textX, (int) textY);
gl.glBegin(GL2.GL_QUADS);
gl.glColor4fv(new float[] {colors[i].getRed() / 255f, colors[i].getGreen() / 255f, colors[i].getBlue() / 255f, 1}, 0);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY + textHeight);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY + textHeight);
gl.glEnd();
}
} else if(orientation == NORTH_EAST) {
gl.glColor4fv(Theme.tooltipBackgroundColor, 0);
gl.glBegin(GL2.GL_TRIANGLES);
gl.glVertex2f(anchorX, anchorY + padding);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX + (0.85f * padding), anchorY + padding);
gl.glEnd();
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f(anchorX, anchorY + padding + boxHeight);
gl.glVertex2f(anchorX, anchorY + padding);
gl.glVertex2f(anchorX + boxWidth, anchorY + padding);
gl.glVertex2f(anchorX + boxWidth, anchorY + padding + boxHeight);
gl.glEnd();
gl.glColor4fv(Theme.tooltipBorderColor, 0);
gl.glBegin(GL2.GL_LINE_LOOP);
gl.glVertex2f(anchorX, anchorY + padding + boxHeight);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX + (0.85f * padding), anchorY + padding);
gl.glVertex2f(anchorX + boxWidth, anchorY + padding);
gl.glVertex2f(anchorX + boxWidth, anchorY + padding + boxHeight);
gl.glEnd();
// draw the text and color boxes
float textX = anchorX + padding + textHeight + Theme.tooltipTextPadding;
for(int i = 0; i < text.length; i++) {
float textY = anchorY + padding + boxHeight - ((i + 1) * (padding + textHeight));
FontUtils.drawTickText(text[i], (int) textX, (int) textY);
gl.glBegin(GL2.GL_QUADS);
gl.glColor4fv(new float[] {colors[i].getRed() / 255f, colors[i].getGreen() / 255f, colors[i].getBlue() / 255f, 1}, 0);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY + textHeight);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY + textHeight);
gl.glEnd();
}
} else if(orientation == SOUTH_WEST) {
gl.glColor4fv(Theme.tooltipBackgroundColor, 0);
gl.glBegin(GL2.GL_TRIANGLES);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX - (0.85f * padding), anchorY - padding);
gl.glVertex2f(anchorX, anchorY - padding);
gl.glEnd();
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f(anchorX - boxWidth, anchorY - padding);
gl.glVertex2f(anchorX - boxWidth, anchorY - padding - boxHeight);
gl.glVertex2f(anchorX, anchorY - padding - boxHeight);
gl.glVertex2f(anchorX, anchorY - padding);
gl.glEnd();
gl.glColor4fv(Theme.tooltipBorderColor, 0);
gl.glBegin(GL2.GL_LINE_LOOP);
gl.glVertex2f(anchorX - boxWidth, anchorY - padding);
gl.glVertex2f(anchorX - boxWidth, anchorY - padding - boxHeight);
gl.glVertex2f(anchorX, anchorY - padding - boxHeight);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX - (0.85f * padding), anchorY - padding);
gl.glEnd();
// draw the text and color boxes
float textX = anchorX - boxWidth + padding + textHeight + Theme.tooltipTextPadding;
for(int i = 0; i < text.length; i++) {
float textY = anchorY - padding - ((i + 1) * (padding + textHeight));
FontUtils.drawTickText(text[i], (int) textX, (int) textY);
gl.glBegin(GL2.GL_QUADS);
gl.glColor4fv(new float[] {colors[i].getRed() / 255f, colors[i].getGreen() / 255f, colors[i].getBlue() / 255f, 1}, 0);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY + textHeight);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY + textHeight);
gl.glEnd();
}
} else if(orientation == SOUTH_EAST) {
gl.glColor4fv(Theme.tooltipBackgroundColor, 0);
gl.glBegin(GL2.GL_TRIANGLES);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX, anchorY - padding);
gl.glVertex2f(anchorX + (0.85f * padding), anchorY - padding);
gl.glEnd();
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f(anchorX, anchorY - padding);
gl.glVertex2f(anchorX, anchorY - padding - boxHeight);
gl.glVertex2f(anchorX + boxWidth, anchorY - padding - boxHeight);
gl.glVertex2f(anchorX + boxWidth, anchorY - padding);
gl.glEnd();
gl.glColor4fv(Theme.tooltipBorderColor, 0);
gl.glBegin(GL2.GL_LINE_LOOP);
gl.glVertex2f(anchorX, anchorY);
gl.glVertex2f(anchorX, anchorY - padding - boxHeight);
gl.glVertex2f(anchorX + boxWidth, anchorY - padding - boxHeight);
gl.glVertex2f(anchorX + boxWidth, anchorY - padding);
gl.glVertex2f(anchorX + (0.85f * padding), anchorY - padding);
gl.glEnd();
// draw the text and color boxes
float textX = anchorX + padding + textHeight + Theme.tooltipTextPadding;
for(int i = 0; i < text.length; i++) {
float textY = anchorY - padding - ((i + 1) * (padding + textHeight));
FontUtils.drawTickText(text[i], (int) textX, (int) textY);
gl.glBegin(GL2.GL_QUADS);
gl.glColor4fv(new float[] {colors[i].getRed() / 255f, colors[i].getGreen() / 255f, colors[i].getBlue() / 255f, 1}, 0);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY + textHeight);
gl.glVertex2f(textX - Theme.tooltipTextPadding - textHeight, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY);
gl.glVertex2f(textX - Theme.tooltipTextPadding, textY + textHeight);
gl.glEnd();
}
}
}
}