summaryrefslogblamecommitdiffstats
path: root/Under-Testing/Website/class/pDraw.class.php
blob: 85e408eb2807d2b16b28999b43b86feaea96583b (plain) (tree)
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
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799






































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                                                                                                                                                                                                                                                            
<?php
 /*
     pDraw - class extension with drawing methods

     Version     : 2.1.2
     Made by     : Jean-Damien POGOLOTTI
     Last Update : 03/08/11

     This file can be distributed under the license you can find at :

                       http://www.pchart.net/license

     You can find the whole class documentation on the pChart web site.
 */

 define("DIRECTION_VERTICAL"		, 690001);
 define("DIRECTION_HORIZONTAL"		, 690002);

 define("SCALE_POS_LEFTRIGHT"		, 690101);
 define("SCALE_POS_TOPBOTTOM"		, 690102);

 define("SCALE_MODE_FLOATING"		, 690201);
 define("SCALE_MODE_START0"		, 690202);
 define("SCALE_MODE_ADDALL"		, 690203);
 define("SCALE_MODE_ADDALL_START0"	, 690204);
 define("SCALE_MODE_MANUAL"		, 690205);

 define("SCALE_SKIP_NONE"		, 690301);
 define("SCALE_SKIP_SAME"		, 690302);
 define("SCALE_SKIP_NUMBERS"		, 690303);

 define("TEXT_ALIGN_TOPLEFT"		, 690401);
 define("TEXT_ALIGN_TOPMIDDLE"		, 690402);
 define("TEXT_ALIGN_TOPRIGHT"		, 690403);
 define("TEXT_ALIGN_MIDDLELEFT"		, 690404);
 define("TEXT_ALIGN_MIDDLEMIDDLE"	, 690405);
 define("TEXT_ALIGN_MIDDLERIGHT"	, 690406);
 define("TEXT_ALIGN_BOTTOMLEFT"		, 690407);
 define("TEXT_ALIGN_BOTTOMMIDDLE"	, 690408);
 define("TEXT_ALIGN_BOTTOMRIGHT"	, 690409);

 define("POSITION_TOP"                  , 690501);
 define("POSITION_BOTTOM"               , 690502);

 define("LABEL_POS_LEFT"		, 690601);
 define("LABEL_POS_CENTER"		, 690602);
 define("LABEL_POS_RIGHT"		, 690603);
 define("LABEL_POS_TOP"			, 690604);
 define("LABEL_POS_BOTTOM"		, 690605);
 define("LABEL_POS_INSIDE"		, 690606);
 define("LABEL_POS_OUTSIDE"		, 690607);

 define("ORIENTATION_HORIZONTAL"	, 690701);
 define("ORIENTATION_VERTICAL"		, 690702);

 define("LEGEND_NOBORDER"		, 690800);
 define("LEGEND_BOX"			, 690801);
 define("LEGEND_ROUND"			, 690802);

 define("LEGEND_VERTICAL"		, 690901);
 define("LEGEND_HORIZONTAL"		, 690902);

 define("LEGEND_FAMILY_BOX"		, 691051);
 define("LEGEND_FAMILY_CIRCLE"		, 691052);
 define("LEGEND_FAMILY_LINE"		, 691053);

 define("DISPLAY_AUTO"			, 691001);
 define("DISPLAY_MANUAL"		, 691002);

 define("LABELING_ALL"			, 691011);
 define("LABELING_DIFFERENT"		, 691012);

 define("BOUND_MIN"			, 691021);
 define("BOUND_MAX"			, 691022);
 define("BOUND_BOTH"			, 691023);

 define("BOUND_LABEL_POS_TOP"		, 691031);
 define("BOUND_LABEL_POS_BOTTOM"	, 691032);
 define("BOUND_LABEL_POS_AUTO"		, 691033);

 define("CAPTION_LEFT_TOP"		, 691041);
 define("CAPTION_RIGHT_BOTTOM"		, 691042);

 define("GRADIENT_SIMPLE"		, 691051);
 define("GRADIENT_EFFECT_CAN"		, 691052);

 define("LABEL_TITLE_NOBACKGROUND"	, 691061);
 define("LABEL_TITLE_BACKGROUND"	, 691062);

 define("LABEL_POINT_NONE"		, 691071);
 define("LABEL_POINT_CIRCLE"		, 691072);
 define("LABEL_POINT_BOX"		, 691073);

 define("PI"		, 3.14159265);
 define("ALL"		, 69);
 define("NONE"		, 31);
 define("AUTO"		, 690000);
 define("OUT_OF_SIGHT"	, -10000000000000);

 class pDraw
  {
   /* Returns the number of drawable series */
   function countDrawableSeries()
    {
     $Results = 0;
     $Data = $this->DataSet->getData();

     foreach($Data["Series"] as $SerieName => $Serie)
      { if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] ) { $Results++; } }

     return($Results);
    }

   /* Fix box coordinates */
   function fixBoxCoordinates($Xa,$Ya,$Xb,$Yb)
    {
     $X1 = min($Xa,$Xb); $Y1 = min($Ya,$Yb);
     $X2 = max($Xa,$Xb); $Y2 = max($Ya,$Yb);

     return(array($X1,$Y1,$X2,$Y2));
    }

   /* Draw a polygon */
   function drawPolygon($Points,$Format="")
    {
     $R			= isset($Format["R"]) ? $Format["R"] : 0;
     $G			= isset($Format["G"]) ? $Format["G"] : 0;
     $B			= isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $NoFill		= isset($Format["NoFill"]) ? $Format["NoFill"] : FALSE;
     $NoBorder		= isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
     $BorderAlpha 	= isset($Format["Alpha"]) ? $Format["Alpha"] : $Alpha / 2;
     $Surrounding	= isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
     $SkipX		= isset($Format["SkipX"]) ? $Format["SkipX"] : OUT_OF_SIGHT;
     $SkipY		= isset($Format["SkipY"]) ? $Format["SkipY"] : OUT_OF_SIGHT;

     /* Calling the ImageFilledPolygon() function over the $Points array will round it */ 	
     $Backup = $Points;

     if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }

     if ( $SkipX != OUT_OF_SIGHT ) { $SkipX = floor($SkipX); }
     if ( $SkipY != OUT_OF_SIGHT ) { $SkipY = floor($SkipY); }

     $RestoreShadow = $this->Shadow;
     if ( !$NoFill )
      {
       if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
        {
         $this->Shadow = FALSE;
         for($i=0;$i<=count($Points)-1;$i=$i+2)
          { $Shadow[] = $Points[$i] + $this->ShadowX; $Shadow[] = $Points[$i+1] + $this->ShadowY; }
         $this->drawPolygon($Shadow,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"NoBorder"=>TRUE));
        }

       $FillColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);

       if ( count($Points) >= 6 )
        { ImageFilledPolygon($this->Picture,$Points,count($Points)/2,$FillColor); }
      }

     if ( !$NoBorder )
      {
       $Points = $Backup;

       if ( $NoFill )
        $BorderSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
       else
        $BorderSettings = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha);

       for($i=0;$i<=count($Points)-1;$i=$i+2)
        {
         if ( isset($Points[$i+2]) )
          {
           if ( !($Points[$i] == $Points[$i+2] && $Points[$i] == $SkipX ) && !($Points[$i+1] == $Points[$i+3] && $Points[$i+1] == $SkipY ) )
            $this->drawLine($Points[$i],$Points[$i+1],$Points[$i+2],$Points[$i+3],$BorderSettings);
          }
         else
          {
           if ( !($Points[$i] == $Points[0] && $Points[$i] == $SkipX ) && !($Points[$i+1] == $Points[1] && $Points[$i+1] == $SkipY ) )
            $this->drawLine($Points[$i],$Points[$i+1],$Points[0],$Points[1],$BorderSettings);
          }
        }
      }

     $this->Shadow = $RestoreShadow;
    }

   /* Apply AALias correction to the rounded box boundaries */
   function offsetCorrection($Value,$Mode)
    {
     $Value = round($Value,1);

     if ( $Value == 0 && $Mode == 1 ) { return(.9); }
     if ( $Value == 0 ) { return(0); }

     if ( $Mode == 1) 
      { if ( $Value == 1 ) { return(.9); }; if ( $Value == .1 ) { return(.9); }; if ( $Value == .2 ) { return(.8); }; if ( $Value == .3 ) { return(.8); }; if ( $Value == .4 ) { return(.7); }; if ( $Value == .5 ) { return(.5); }; if ( $Value == .6 ) { return(.8); }; if ( $Value == .7 ) { return(.7); }; if ( $Value == .8 ) { return(.6); }; if ( $Value == .9 ) { return(.9); }; }

     if ( $Mode == 2) 
      { if ( $Value == 1 ) { return(.9); }; if ( $Value == .1 ) { return(.1); }; if ( $Value == .2 ) { return(.2); }; if ( $Value == .3 ) { return(.3); }; if ( $Value == .4 ) { return(.4); }; if ( $Value == .5 ) { return(.5); }; if ( $Value == .6 ) { return(.8); }; if ( $Value == .7 ) { return(.7); }; if ( $Value == .8 ) { return(.8); }; if ( $Value == .9 ) { return(.9); }; }

     if ( $Mode == 3) 
      { if ( $Value == 1 ) { return(.1); }; if ( $Value == .1 ) { return(.1); }; if ( $Value == .2 ) { return(.2); }; if ( $Value == .3 ) { return(.3); }; if ( $Value == .4 ) { return(.4); }; if ( $Value == .5 ) { return(.9); }; if ( $Value == .6 ) { return(.6); }; if ( $Value == .7 ) { return(.7); }; if ( $Value == .8 ) { return(.4); }; if ( $Value == .9 ) { return(.5); }; }

     if ( $Mode == 4) 
      { if ( $Value == 1 ) { return(-1); }; if ( $Value == .1 ) { return(.1); }; if ( $Value == .2 ) { return(.2); }; if ( $Value == .3 ) { return(.3); }; if ( $Value == .4 ) { return(.1); }; if ( $Value == .5 ) { return(-.1); }; if ( $Value == .6 ) { return(.8); }; if ( $Value == .7 ) { return(.1); }; if ( $Value == .8 ) { return(.1); }; if ( $Value == .9 ) { return(.1); }; }
    }

   /* Draw a rectangle with rounded corners */
   function drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$Format="")
    {
     $R	    = isset($Format["R"]) ? $Format["R"] : 0;
     $G	    = isset($Format["G"]) ? $Format["G"] : 0;
     $B	    = isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;

     list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);

     if ( $X2 - $X1 < $Radius ) { $Radius = floor((($X2-$X1))/2); }
     if ( $Y2 - $Y1 < $Radius ) { $Radius = floor((($Y2-$Y1))/2); }

     $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE);

     if ( $Radius <= 0 ) { $this->drawRectangle($X1,$Y1,$X2,$Y2,$Color); return(0); }

     if ( $this->Antialias )
      {
       $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$Color);
       $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$Color);
       $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$Color);
       $this->drawLine($X1,$Y1+$Radius,$X1,$Y2-$Radius,$Color);
      }
     else
      {
       $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
       imageline($this->Picture,$X1+$Radius,$Y1,$X2-$Radius,$Y1,$Color);
       imageline($this->Picture,$X2,$Y1+$Radius,$X2,$Y2-$Radius,$Color);
       imageline($this->Picture,$X2-$Radius,$Y2,$X1+$Radius,$Y2,$Color);
       imageline($this->Picture,$X1,$Y1+$Radius,$X1,$Y2-$Radius,$Color);
      }

     $Step = 360 / (2 * PI * $Radius);
     for($i=0;$i<=90;$i=$i+$Step)
      {
       $X = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
       $Y = sin(($i+180)*PI/180) * $Radius + $Y1 + $Radius;
       $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));

       $X = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
       $Y = sin(($i+90)*PI/180) * $Radius + $Y2 - $Radius;
       $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));

       $X = cos($i*PI/180) * $Radius + $X2 - $Radius;
       $Y = sin($i*PI/180) * $Radius + $Y2 - $Radius;
       $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));

       $X = cos(($i+270)*PI/180) * $Radius + $X2 - $Radius;
       $Y = sin(($i+270)*PI/180) * $Radius + $Y1 + $Radius;
       $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
      }
    }

   /* Draw a rectangle with rounded corners */
   function drawRoundedFilledRectangle($X1,$Y1,$X2,$Y2,$Radius,$Format="")
    {
     $R			= isset($Format["R"]) ? $Format["R"] : 0;
     $G			= isset($Format["G"]) ? $Format["G"] : 0;
     $B			= isset($Format["B"]) ? $Format["B"] : 0;
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
     $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $Surrounding	= isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;

     /* Temporary fix for AA issue */
     $Y1 = floor($Y1); $Y2 = floor($Y2); $X1 = floor($X1); $X2 = floor($X2);

     if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
     if ( $BorderR == -1 ) { $BorderR = $R; $BorderG = $G; $BorderB = $B; }

     list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);

     if ( $X2 - $X1 < $Radius*2 ) { $Radius = floor((($X2-$X1))/4); }
     if ( $Y2 - $Y1 < $Radius*2 ) { $Radius = floor((($Y2-$Y1))/4); }

     $RestoreShadow = $this->Shadow;
     if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
      {
       $this->Shadow = FALSE;
       $this->drawRoundedFilledRectangle($X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,$Radius,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
      }

     $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE);

     if ( $Radius <= 0 ) { $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color); return(0); }

     $YTop    = $Y1+$Radius;
     $YBottom = $Y2-$Radius;

     $Step = 360 / (2 * PI * $Radius);
     $Positions = ""; $Radius--; $MinY = ""; $MaxY = "";
     for($i=0;$i<=90;$i=$i+$Step)
      {
       $Xp1 = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
       $Xp2 = cos(((90-$i)+270)*PI/180) * $Radius + $X2 - $Radius;
       $Yp  = floor(sin(($i+180)*PI/180) * $Radius + $YTop);
       if ( $MinY == "" || $Yp > $MinY ) { $MinY = $Yp; }

       if ( $Xp2 >= floor($X2) ) { $Xp2--; }
       $Xp1++;

       if ( !isset($Positions[$Yp]) )
        { $Positions[$Yp]["X1"] = $Xp1; $Positions[$Yp]["X2"] = $Xp2; }
       else
        { $Positions[$Yp]["X1"] = ($Positions[$Yp]["X1"]+$Xp1)/2; $Positions[$Yp]["X2"] = ($Positions[$Yp]["X2"]+$Xp2)/2; }

       $Xp1 = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
       $Xp2 = cos((90-$i)*PI/180) * $Radius + $X2 - $Radius;
       $Yp  = floor(sin(($i+90)*PI/180) * $Radius + $YBottom);
       if ( $MaxY == "" || $Yp < $MaxY ) { $MaxY = $Yp; }

       if ( $Xp2 >= floor($X2) ) { $Xp2--; }
       $Xp1++;

       if ( !isset($Positions[$Yp]) )
        { $Positions[$Yp]["X1"] = $Xp1; $Positions[$Yp]["X2"] = $Xp2; }
       else
        { $Positions[$Yp]["X1"] = ($Positions[$Yp]["X1"]+$Xp1)/2; $Positions[$Yp]["X2"] = ($Positions[$Yp]["X2"]+$Xp2)/2; }
      }

     $ManualColor  = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
     foreach($Positions as $Yp => $Bounds)
      {
       $X1 = $Bounds["X1"]; $X1Dec = $this->getFirstDecimal($X1); if ( $X1Dec != 0 ) { $X1 = floor($X1)+1; }
       $X2 = $Bounds["X2"]; $X2Dec = $this->getFirstDecimal($X2); if ( $X2Dec != 0 ) { $X2 = floor($X2)-1; }
       imageline($this->Picture,$X1,$Yp,$X2,$Yp,$ManualColor);
      }
     $this->drawFilledRectangle($X1,$MinY+1,floor($X2),$MaxY-1,$Color);

     $Radius++;
     $this->drawRoundedRectangle($X1,$Y1,$X2+1,$Y2-1,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));

     $this->Shadow = $RestoreShadow;
    }

   /* Draw a rectangle with rounded corners */
   function drawRoundedFilledRectangle_deprecated($X1,$Y1,$X2,$Y2,$Radius,$Format="")
    {
     $R			= isset($Format["R"]) ? $Format["R"] : 0;
     $G			= isset($Format["G"]) ? $Format["G"] : 0;
     $B			= isset($Format["B"]) ? $Format["B"] : 0;
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
     $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $Surrounding	= isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;

     if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
     if ( $BorderR == -1 ) { $BorderR = $R; $BorderG = $G; $BorderB = $B; }

     list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);

     if ( $X2 - $X1 < $Radius ) { $Radius = floor((($X2-$X1)+2)/2); }
     if ( $Y2 - $Y1 < $Radius ) { $Radius = floor((($Y2-$Y1)+2)/2); }

     $RestoreShadow = $this->Shadow;
     if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
      {
       $this->Shadow = FALSE;
       $this->drawRoundedFilledRectangle($X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,$Radius,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
      }

     if ( $this->getFirstDecimal($X2) >= 5 )  { $XOffset2 = 1; } else { $XOffset2 = 0; }
     if ( $this->getFirstDecimal($X1) <= 5 )  { $XOffset1 = 1; } else { $XOffset1 = 0; }

     if ( !$this->Antialias ) { $XOffset1 = 1; $XOffset2 = 1; }

     $YTop    = floor($Y1+$Radius);
     $YBottom = floor($Y2-$Radius);

     $this->drawFilledRectangle($X1-$XOffset1,$YTop,$X2+$XOffset2,$YBottom,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE));

     $Step = 360 / (2 * PI * $Radius);
     $Color  = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
     $Color2 = $this->allocateColor($this->Picture,255,0,0,$Alpha);
     $Drawn = "";

     if ( $Alpha < 100 )  { $Drawn[$YTop] = FALSE; }
     if ( $Alpha < 100 )  { $Drawn[$YBottom] = TRUE; }
     
     for($i=0;$i<=90;$i=$i+$Step)
      {
       $Xp1 = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
       $Xp2 = cos(((90-$i)+270)*PI/180) * $Radius + $X2 - $Radius;
       $Yp  = sin(($i+180)*PI/180) * $Radius + $YTop;

       if ( $this->getFirstDecimal($Xp1) > 5 )  { $XOffset1 = 1; } else { $XOffset1 = 0; }
       if ( $this->getFirstDecimal($Xp2) > 5 )  { $XOffset2 = 1; } else { $XOffset2 = 0; }
       if ( $this->getFirstDecimal($Yp) > 5 )  { $YOffset = 1; } else { $YOffset = 0; }

       if ( !isset($Drawn[$Yp+$YOffset]) || $Alpha == 100 )
        imageline($this->Picture,$Xp1+$XOffset1,$Yp+$YOffset,$Xp2+$XOffset2,$Yp+$YOffset,$Color);

       $Drawn[$Yp+$YOffset] = $Xp2;

       $Xp1 = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
       $Xp2 = cos((90-$i)*PI/180) * $Radius + $X2 - $Radius;
       $Yp  = sin(($i+90)*PI/180) * $Radius + $YBottom;

       if ( $this->getFirstDecimal($Xp1) > 7 )  { $XOffset1 = 1; } else { $XOffset1 = 0; }
       if ( $this->getFirstDecimal($Xp2) > 7 )  { $XOffset2 = 1; } else { $XOffset2 = 0; }
       if ( $this->getFirstDecimal($Yp) > 5 )  { $YOffset = 1; } else { $YOffset = 0; }

       if ( !isset($Drawn[$Yp+$YOffset]) || $Alpha == 100 )
        imageline($this->Picture,$Xp1+$XOffset1,$Yp+$YOffset,$Xp2+$XOffset2,$Yp+$YOffset,$Color);

       $Drawn[$Yp+$YOffset] = $Xp2;
      }

     $this->drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));

     $this->Shadow = $RestoreShadow;
    }

   /* Draw a rectangle */
   function drawRectangle($X1,$Y1,$X2,$Y2,$Format="")
    {
     $R		= isset($Format["R"]) ? $Format["R"] : 0;
     $G		= isset($Format["G"]) ? $Format["G"] : 0;
     $B		= isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha	= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $Ticks	= isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
     $NoAngle	= isset($Format["NoAngle"]) ? $Format["NoAngle"] : FALSE;

     if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
     if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }

     if ( $this->Antialias )
      {
       if ( $NoAngle )
        {
         $this->drawLine($X1+1,$Y1,$X2-1,$Y1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
         $this->drawLine($X2,$Y1+1,$X2,$Y2-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
         $this->drawLine($X2-1,$Y2,$X1+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
         $this->drawLine($X1,$Y1+1,$X1,$Y2-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
        }
       else
        {
         $this->drawLine($X1+1,$Y1,$X2-1,$Y1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
         $this->drawLine($X2,$Y1,$X2,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
         $this->drawLine($X2-1,$Y2,$X1+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
         $this->drawLine($X1,$Y1,$X1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
        }
      }
     else
      {
       $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
       imagerectangle($this->Picture,$X1,$Y1,$X2,$Y2,$Color);
      }
    }

   /* Draw a filled rectangle */
   function drawFilledRectangle($X1,$Y1,$X2,$Y2,$Format="")
    {
     $R			= isset($Format["R"]) ? $Format["R"] : 0;
     $G			= isset($Format["G"]) ? $Format["G"] : 0;
     $B			= isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
     $BorderAlpha	= isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha;
     $Surrounding	= isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
     $Ticks		= isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
     $NoAngle		= isset($Format["NoAngle"]) ? $Format["NoAngle"] : NULL;
     $Dash		= isset($Format["Dash"]) ? $Format["Dash"] : FALSE;
     $DashStep		= isset($Format["DashStep"]) ? $Format["DashStep"] : 4;
     $DashR		= isset($Format["DashR"]) ? $Format["DashR"] : 0;
     $DashG		= isset($Format["DashG"]) ? $Format["DashG"] : 0;
     $DashB		= isset($Format["DashB"]) ? $Format["DashB"] : 0;
     $NoBorder		= isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;

     if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }

     if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
     if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }

     $RestoreShadow = $this->Shadow;
     if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
      {
       $this->Shadow = FALSE;
       $this->drawFilledRectangle($X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Ticks"=>$Ticks,"NoAngle"=>$NoAngle));
      }

     $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
     if ( $NoAngle )
      {
       imagefilledrectangle($this->Picture,ceil($X1)+1,ceil($Y1),floor($X2)-1,floor($Y2),$Color);
       imageline($this->Picture,ceil($X1),ceil($Y1)+1,ceil($X1),floor($Y2)-1,$Color);
       imageline($this->Picture,floor($X2),ceil($Y1)+1,floor($X2),floor($Y2)-1,$Color);
      }
     else
      imagefilledrectangle($this->Picture,ceil($X1),ceil($Y1),floor($X2),floor($Y2),$Color);

     if ( $Dash )
      {
       if ( $BorderR != -1 ) { $iX1=$X1+1; $iY1=$Y1+1; $iX2=$X2-1; $iY2=$Y2-1; } else { $iX1=$X1; $iY1=$Y1; $iX2=$X2; $iY2=$Y2; }

       $Color = $this->allocateColor($this->Picture,$DashR,$DashG,$DashB,$Alpha);
       $Y=$iY1-$DashStep;
       for($X=$iX1; $X<=$iX2+($iY2-$iY1); $X=$X+$DashStep)
        {
         $Y=$Y+$DashStep;
         if ( $X > $iX2 ) { $Xa = $X-($X-$iX2); $Ya = $iY1+($X-$iX2); } else { $Xa = $X; $Ya = $iY1; }
         if ( $Y > $iY2 ) { $Xb = $iX1+($Y-$iY2); $Yb = $Y-($Y-$iY2); } else { $Xb = $iX1; $Yb = $Y; }
         imageline($this->Picture,$Xa,$Ya,$Xb,$Yb,$Color);
        }
      }

     if ( $this->Antialias && !$NoBorder )
      {
       if ( $X1 < ceil($X1) )
        {
         $AlphaA = $Alpha * (ceil($X1) - $X1);
         $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
         imageline($this->Picture,ceil($X1)-1,ceil($Y1),ceil($X1)-1,floor($Y2),$Color);
        }

       if ( $Y1 < ceil($Y1) )
        {
         $AlphaA = $Alpha * (ceil($Y1) - $Y1);
         $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
         imageline($this->Picture,ceil($X1),ceil($Y1)-1,floor($X2),ceil($Y1)-1,$Color);
        }

       if ( $X2 > floor($X2) )
        {
         $AlphaA = $Alpha * (.5-($X2 - floor($X2)));
         $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
         imageline($this->Picture,floor($X2)+1,ceil($Y1),floor($X2)+1,floor($Y2),$Color);
        } 

       if ( $Y2 > floor($Y2) )
        {
         $AlphaA = $Alpha * (.5-($Y2 - floor($Y2)));
         $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
         imageline($this->Picture,ceil($X1),floor($Y2)+1,floor($X2),floor($Y2)+1,$Color);
        }
      }

     if ( $BorderR != -1 )
      $this->drawRectangle($X1,$Y1,$X2,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$Ticks,"NoAngle"=>$NoAngle));

     $this->Shadow = $RestoreShadow;
    }

   /* Draw a rectangular marker of the specified size */
   function drawRectangleMarker($X,$Y,$Format="")
    {
     $Size = isset($Format["Size"]) ? $Format["Size"] : 4;

     $HalfSize = floor($Size/2);
     $this->drawFilledRectangle($X-$HalfSize,$Y-$HalfSize,$X+$HalfSize,$Y+$HalfSize,$Format);
    }

   /* Drawn a spline based on the bezier function */
   function drawSpline($Coordinates,$Format="")
    {
     $R		= isset($Format["R"]) ? $Format["R"] : 0;
     $G		= isset($Format["G"]) ? $Format["G"] : 0;
     $B		= isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha	= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $Force	= isset($Format["Force"]) ? $Format["Force"] : 30;
     $Forces	= isset($Format["Forces"]) ? $Format["Forces"] : NULL;
     $ShowC	= isset($Format["ShowControl"]) ? $Format["ShowControl"] : FALSE;
     $Ticks	= isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
     $PathOnly	= isset($Format["PathOnly"]) ? $Format["PathOnly"] : FALSE;
     $Weight	= isset($Format["Weight"]) ? $Format["Weight"] : NULL;

     $Cpt = NULL; $Mode = NULL; $Result = "";
     for($i=1;$i<=count($Coordinates)-1;$i++)
      {
       $X1 = $Coordinates[$i-1][0]; $Y1 = $Coordinates[$i-1][1];
       $X2 = $Coordinates[$i][0];   $Y2 = $Coordinates[$i][1];

       if ( $Forces != NULL ) { $Force = $Forces[$i]; }

       /* First segment */
       if ( $i == 1 )
        { $Xv1 = $X1; $Yv1 = $Y1; }
       else
        {
         $Angle1 = $this->getAngle($XLast,$YLast,$X1,$Y1);
         $Angle2 = $this->getAngle($X1,$Y1,$X2,$Y2);
         $XOff = cos($Angle2 * PI / 180) * $Force + $X1;
         $YOff = sin($Angle2 * PI / 180) * $Force + $Y1;

         $Xv1 = cos($Angle1 * PI / 180) * $Force + $XOff;
         $Yv1 = sin($Angle1 * PI / 180) * $Force + $YOff;
        }

       /* Last segment */
       if ( $i == count($Coordinates)-1 )
        { $Xv2 = $X2; $Yv2 = $Y2; }
       else
        {
         $Angle1 = $this->getAngle($X2,$Y2,$Coordinates[$i+1][0],$Coordinates[$i+1][1]);
         $Angle2 = $this->getAngle($X1,$Y1,$X2,$Y2);
         $XOff = cos(($Angle2+180) * PI / 180) * $Force + $X2;
         $YOff = sin(($Angle2+180) * PI / 180) * $Force + $Y2;

         $Xv2 = cos(($Angle1+180) * PI / 180) * $Force + $XOff;
         $Yv2 = sin(($Angle1+180) * PI / 180) * $Force + $YOff;
        }

       $Path = $this->drawBezier($X1,$Y1,$X2,$Y2,$Xv1,$Yv1,$Xv2,$Yv2,$Format);
       if ($PathOnly) { $Result[] = $Path; }

       $XLast = $X1; $YLast = $Y1;
      }

     return($Result);
    }

   /* Draw a bezier curve with two controls points */
   function drawBezier($X1,$Y1,$X2,$Y2,$Xv1,$Yv1,$Xv2,$Yv2,$Format="")
    {
     $R		= isset($Format["R"]) ? $Format["R"] : 0;
     $G		= isset($Format["G"]) ? $Format["G"] : 0;
     $B		= isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha	= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $ShowC	= isset($Format["ShowControl"]) ? $Format["ShowControl"] : FALSE;
     $Segments	= isset($Format["Segments"]) ? $Format["Segments"] : NULL;
     $Ticks	= isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
     $NoDraw    = isset($Format["NoDraw"]) ? $Format["NoDraw"] : FALSE;
     $PathOnly  = isset($Format["PathOnly"]) ? $Format["PathOnly"] : FALSE;
     $Weight    = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
     $DrawArrow		= isset($Format["DrawArrow"]) ? $Format["DrawArrow"] : FALSE;
     $ArrowSize		= isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 10;
     $ArrowRatio	= isset($Format["ArrowRatio"]) ? $Format["ArrowRatio"] : .5;
     $ArrowTwoHeads	= isset($Format["ArrowTwoHeads"]) ? $Format["ArrowTwoHeads"] : FALSE;

     if ( $Segments == NULL )
      {
       $Length    = $this->getLength($X1,$Y1,$X2,$Y2);
       $Precision = ($Length*125)/1000;
      }
     else
      $Precision = $Segments;

     $P[0]["X"] = $X1;  $P[0]["Y"] = $Y1;
     $P[1]["X"] = $Xv1; $P[1]["Y"] = $Yv1;
     $P[2]["X"] = $Xv2; $P[2]["Y"] = $Yv2;
     $P[3]["X"] = $X2;  $P[3]["Y"] = $Y2;

     /* Compute the bezier points */
     $Q = ""; $ID = 0; $Path = "";
     for($i=0;$i<=$Precision;$i=$i+1)
      {
       $u = $i / $Precision;

       $C    = "";
       $C[0] = (1 - $u) * (1 - $u) * (1 - $u);
       $C[1] = ($u * 3) * (1 - $u) * (1 - $u);
       $C[2] = 3 * $u * $u * (1 - $u);
       $C[3] = $u * $u * $u;

       for($j=0;$j<=3;$j++)
        {
         if ( !isset($Q[$ID]) ) { $Q[$ID] = ""; }
         if ( !isset($Q[$ID]["X"]) ) { $Q[$ID]["X"] = 0; }
         if ( !isset($Q[$ID]["Y"]) ) { $Q[$ID]["Y"] = 0; }

         $Q[$ID]["X"] = $Q[$ID]["X"] + $P[$j]["X"] * $C[$j];
         $Q[$ID]["Y"] = $Q[$ID]["Y"] + $P[$j]["Y"] * $C[$j];
        }
       $ID++;
      }        
     $Q[$ID]["X"] = $X2; $Q[$ID]["Y"] = $Y2;

     if ( !$NoDraw )
      {
       /* Display the control points */
       if ( $ShowC && !$PathOnly )
        {
         $Xv1 = floor($Xv1); $Yv1 = floor($Yv1); $Xv2 = floor($Xv2); $Yv2 = floor($Yv2);

         $this->drawLine($X1,$Y1,$X2,$Y2,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>30));

         $MyMarkerSettings = array("R"=>255,"G"=>0,"B"=>0,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
         $this->drawRectangleMarker($Xv1,$Yv1,$MyMarkerSettings);
         $this->drawText($Xv1+4,$Yv1,"v1");
         $MyMarkerSettings = array("R"=>0,"G"=>0,"B"=>255,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
         $this->drawRectangleMarker($Xv2,$Yv2,$MyMarkerSettings);
         $this->drawText($Xv2+4,$Yv2,"v2");
        }

       /* Draw the bezier */
       $LastX = NULL; $LastY = NULL; $Cpt = NULL; $Mode = NULL; $ArrowS = NULL;
       foreach ($Q as $Key => $Point)
        {
         $X = $Point["X"]; $Y = $Point["Y"];

         /* Get the first segment */
         if ( $ArrowS == NULL && $LastX != NULL && $LastY != NULL )
          { $ArrowS["X2"] = $LastX; $ArrowS["Y2"] = $LastY; $ArrowS["X1"] = $X; $ArrowS["Y1"] = $Y; }

         if ( $LastX != NULL && $LastY != NULL && !$PathOnly)
          list($Cpt,$Mode) = $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Cpt"=>$Cpt,"Mode"=>$Mode,"Weight"=>$Weight));

         /* Get the last segment */
         $ArrowE["X1"] = $LastX; $ArrowE["Y1"] = $LastY; $ArrowE["X2"] = $X; $ArrowE["Y2"] = $Y;

         $LastX = $X; $LastY = $Y;
        }

       if ( $DrawArrow && !$PathOnly )
        {
         $ArrowSettings = array("FillR"=>$R,"FillG"=>$G,"FillB"=>$B,"Alpha"=>$Alpha,"Size"=>$ArrowSize,"Ratio"=>$ArrowRatio);
         if ( $ArrowTwoHeads )
          $this->drawArrow($ArrowS["X1"],$ArrowS["Y1"],$ArrowS["X2"],$ArrowS["Y2"],$ArrowSettings);

         $this->drawArrow($ArrowE["X1"],$ArrowE["Y1"],$ArrowE["X2"],$ArrowE["Y2"],$ArrowSettings);
        }
      }
     return($Q);
    }

   /* Draw a line between two points */
   function drawLine($X1,$Y1,$X2,$Y2,$Format="")
    {
     $R		= isset($Format["R"]) ? $Format["R"] : 0;
     $G		= isset($Format["G"]) ? $Format["G"] : 0;
     $B		= isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha	= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $Ticks	= isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
     $Cpt	= isset($Format["Cpt"]) ? $Format["Cpt"] : 1;
     $Mode	= isset($Format["Mode"]) ? $Format["Mode"] : 1;
     $Weight	= isset($Format["Weight"]) ? $Format["Weight"] : NULL;
     $Threshold	= isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;

     if ( $this->Antialias == FALSE && $Ticks == NULL )
      {
       if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
        {
         $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
         imageline($this->Picture,$X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,$ShadowColor);
        }

       $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
       imageline($this->Picture,$X1,$Y1,$X2,$Y2,$Color);
       return(0);
      }

     $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1));  
     if ( $Distance == 0 ) { return(-1); }

     /* Derivative algorithm for overweighted lines, re-route to polygons primitives */
     if ( $Weight != NULL )
      {
       $Angle        = $this->getAngle($X1,$Y1,$X2,$Y2);
       $PolySettings = array ("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderAlpha"=>$Alpha);

       if ( $Ticks == NULL )
        {
         $Points   = ""; 
         $Points[] = cos(deg2rad($Angle-90)) * $Weight + $X1; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Y1;
         $Points[] = cos(deg2rad($Angle+90)) * $Weight + $X1; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Y1;
         $Points[] = cos(deg2rad($Angle+90)) * $Weight + $X2; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Y2;
         $Points[] = cos(deg2rad($Angle-90)) * $Weight + $X2; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Y2;

         $this->drawPolygon($Points,$PolySettings);
        }
       else
        {
         for($i=0;$i<=$Distance;$i=$i+$Ticks*2)
          {
           $Xa = (($X2-$X1)/$Distance) * $i + $X1; $Ya = (($Y2-$Y1)/$Distance) * $i + $Y1;
           $Xb = (($X2-$X1)/$Distance) * ($i+$Ticks) + $X1; $Yb = (($Y2-$Y1)/$Distance) * ($i+$Ticks) + $Y1;

           $Points   = ""; 
           $Points[] = cos(deg2rad($Angle-90)) * $Weight + $Xa; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Ya;
           $Points[] = cos(deg2rad($Angle+90)) * $Weight + $Xa; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Ya;
           $Points[] = cos(deg2rad($Angle+90)) * $Weight + $Xb; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Yb;
           $Points[] = cos(deg2rad($Angle-90)) * $Weight + $Xb; $Points[] = sin(deg2rad($Angle-90)) * $Weight 	+ $Yb;

           $this->drawPolygon($Points,$PolySettings);
          }
        }

       return(1);
      }

     $XStep = ($X2-$X1) / $Distance;
     $YStep = ($Y2-$Y1) / $Distance;

     for($i=0;$i<=$Distance;$i++)
      {
       $X = $i * $XStep + $X1;
       $Y = $i * $YStep + $Y1;

       $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);

       if ( $Threshold != NULL )
        {
         foreach($Threshold as $Key => $Parameters)
          {
           if ( $Y <= $Parameters["MinX"] && $Y >= $Parameters["MaxX"])
            {
             if ( isset($Parameters["R"]) ) { $RT = $Parameters["R"]; } else { $RT = 0; }
             if ( isset($Parameters["G"]) ) { $GT = $Parameters["G"]; } else { $GT = 0; }
             if ( isset($Parameters["B"]) ) { $BT = $Parameters["B"]; } else { $BT = 0; }
             if ( isset($Parameters["Alpha"]) ) { $AlphaT = $Parameters["Alpha"]; } else { $AlphaT = 0; }
             $Color = array("R"=>$RT,"G"=>$GT,"B"=>$BT,"Alpha"=>$AlphaT);
            }
          }
        }

       if ( $Ticks != NULL )
        {
         if ( $Cpt % $Ticks == 0 )
          { $Cpt = 0; if ( $Mode == 1 ) { $Mode = 0; } else { $Mode = 1; } }

         if ( $Mode == 1 )
          $this->drawAntialiasPixel($X,$Y,$Color);

         $Cpt++;
        }
       else
        $this->drawAntialiasPixel($X,$Y,$Color);
      }

     return(array($Cpt,$Mode));
    }

   /* Draw a circle */
   function drawCircle($Xc,$Yc,$Height,$Width,$Format="")
    {
     $R	    = isset($Format["R"]) ? $Format["R"] : 0;
     $G	    = isset($Format["G"]) ? $Format["G"] : 0;
     $B	    = isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;

     $Height	= abs($Height);
     $Width	= abs($Width);

     if ( $Height == 0 ) { $Height = 1; }
     if ( $Width == 0 )  { $Width = 1; }
     $Xc = floor($Xc); $Yc = floor($Yc);

     $RestoreShadow = $this->Shadow;
     if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
      {
       $this->Shadow = FALSE;
       $this->drawCircle($Xc+$this->ShadowX,$Yc+$this->ShadowY,$Height,$Width,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Ticks"=>$Ticks));
      }

     if ( $Width == 0 ) { $Width = $Height; }
     if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
     if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
     if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }

     $Step = 360 / (2 * PI * max($Width,$Height));
     $Mode = 1; $Cpt = 1;
     for($i=0;$i<=360;$i=$i+$Step)
      {
       $X = cos($i*PI/180) * $Height + $Xc;
       $Y = sin($i*PI/180) * $Width + $Yc;

       if ( $Ticks != NULL )
        {
         if ( $Cpt % $Ticks == 0 )
          { $Cpt = 0; if ( $Mode == 1 ) { $Mode = 0; } else { $Mode = 1; } }

         if ( $Mode == 1 )
          $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));

         $Cpt++;
        }
       else
        $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));

      }
     $this->Shadow = $RestoreShadow;
    }

   /* Draw a filled circle */
   function drawFilledCircle($X,$Y,$Radius,$Format="")
    {
     $R			= isset($Format["R"]) ? $Format["R"] : 0;
     $G			= isset($Format["G"]) ? $Format["G"] : 0;
     $B			= isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
     $BorderAlpha	= isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha;
     $Ticks     	= isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
     $Surrounding 	= isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;

     if ( $Radius == 0 ) { $Radius = 1; }
     if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
     $X = floor($X); $Y = floor($Y);

     $Radius = abs($Radius);

     $RestoreShadow = $this->Shadow;
     if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
      {
       $this->Shadow = FALSE;
       $this->drawFilledCircle($X+$this->ShadowX,$Y+$this->ShadowY,$Radius,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Ticks"=>$Ticks));
      }

     $this->Mask  = "";
     $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
     for ($i=0; $i<=$Radius*2; $i++)
      {
       $Slice  = sqrt($Radius * $Radius - ($Radius - $i) * ($Radius - $i));
       $XPos   = floor($Slice);
       $YPos   = $Y + $i - $Radius;
       $AAlias = $Slice - floor($Slice);

       $this->Mask[$X-$XPos][$YPos] = TRUE;
       $this->Mask[$X+$XPos][$YPos] = TRUE;
       imageline($this->Picture,$X-$XPos,$YPos,$X+$XPos,$YPos,$Color);
      }
     if ( $this->Antialias )
      $this->drawCircle($X,$Y,$Radius,$Radius,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));

     $this->Mask = "";

     if ( $BorderR != -1 )
      $this->drawCircle($X,$Y,$Radius,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$Ticks));

     $this->Shadow	= $RestoreShadow;
    }

   /* Write text */
   function drawText($X,$Y,$Text,$Format="")
    {
     $R			= isset($Format["R"]) ? $Format["R"] : $this->FontColorR;
     $G			= isset($Format["G"]) ? $Format["G"] : $this->FontColorG;
     $B			= isset($Format["B"]) ? $Format["B"] : $this->FontColorB;
     $Angle		= isset($Format["Angle"]) ? $Format["Angle"] : 0;
     $Align		= isset($Format["Align"]) ? $Format["Align"] : TEXT_ALIGN_BOTTOMLEFT;
     $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : $this->FontColorA;
     $FontName		= isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
     $FontSize		= isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
     $ShowOrigine	= isset($Format["ShowOrigine"]) ? $Format["ShowOrigine"] : FALSE;
     $TOffset		= isset($Format["TOffset"]) ? $Format["TOffset"] : 2;
     $DrawBox		= isset($Format["DrawBox"]) ? $Format["DrawBox"] : FALSE;
     $DrawBoxBorder	= isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : TRUE;
     $BorderOffset	= isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 6;
     $BoxRounded	= isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : FALSE;
     $RoundedRadius	= isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 6;
     $BoxR		= isset($Format["BoxR"]) ? $Format["BoxR"] : 255;
     $BoxG		= isset($Format["BoxG"]) ? $Format["BoxG"] : 255;
     $BoxB		= isset($Format["BoxB"]) ? $Format["BoxB"] : 255;
     $BoxAlpha		= isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 50;
     $BoxSurrounding	= isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
     $BoxBorderR	= isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
     $BoxBorderG	= isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
     $BoxBorderB	= isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
     $BoxBorderAlpha	= isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 50;
     $NoShadow		= isset($Format["NoShadow"]) ? $Format["NoShadow"] : FALSE;

     $Shadow = $this->Shadow;
     if ( $NoShadow ) { $this->Shadow = FALSE; }

     if ( $BoxSurrounding != "" ) { $BoxBorderR = $BoxR - $BoxSurrounding; $BoxBorderG = $BoxG - $BoxSurrounding; $BoxBorderB = $BoxB - $BoxSurrounding; $BoxBorderAlpha = $Boxalpha; }

     if ( $ShowOrigine )
      {
       $MyMarkerSettings = array("R"=>255,"G"=>0,"B"=>0,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
       $this->drawRectangleMarker($X,$Y,$MyMarkerSettings);
      }

     $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,$Angle,$Text);

     if ( $DrawBox && ($Angle == 0 || $Angle == 90 || $Angle == 180 || $Angle == 270))
      {
       $T[0]["X"]=0;$T[0]["Y"]=0;$T[1]["X"]=0;$T[1]["Y"]=0;$T[2]["X"]=0;$T[2]["Y"]=0;$T[3]["X"]=0;$T[3]["Y"]=0;
       if ( $Angle == 0 ) { $T[0]["X"]=-$TOffset;$T[0]["Y"]=$TOffset;$T[1]["X"]=$TOffset;$T[1]["Y"]=$TOffset;$T[2]["X"]=$TOffset;$T[2]["Y"]=-$TOffset;$T[3]["X"]=-$TOffset;$T[3]["Y"]=-$TOffset; }

       $X1 = min($TxtPos[0]["X"],$TxtPos[1]["X"],$TxtPos[2]["X"],$TxtPos[3]["X"]) - $BorderOffset + 3;
       $Y1 = min($TxtPos[0]["Y"],$TxtPos[1]["Y"],$TxtPos[2]["Y"],$TxtPos[3]["Y"]) - $BorderOffset;
       $X2 = max($TxtPos[0]["X"],$TxtPos[1]["X"],$TxtPos[2]["X"],$TxtPos[3]["X"]) + $BorderOffset + 3;
       $Y2 = max($TxtPos[0]["Y"],$TxtPos[1]["Y"],$TxtPos[2]["Y"],$TxtPos[3]["Y"]) + $BorderOffset - 3;

       $X1 = $X1 - $TxtPos[$Align]["X"] + $X + $T[0]["X"];
       $Y1 = $Y1 - $TxtPos[$Align]["Y"] + $Y + $T[0]["Y"];
       $X2 = $X2 - $TxtPos[$Align]["X"] + $X + $T[0]["X"];
       $Y2 = $Y2 - $TxtPos[$Align]["Y"] + $Y + $T[0]["Y"];

       $Settings = array("R"=>$BoxR,"G"=>$BoxG,"B"=>$BoxB,"Alpha"=>$BoxAlpha,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"BorderAlpha"=>$BoxBorderAlpha);

       if ( $BoxRounded )
        { $this->drawRoundedFilledRectangle($X1,$Y1,$X2,$Y2,$RoundedRadius,$Settings); }
       else
        { $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Settings); }
      }

     $X = $X - $TxtPos[$Align]["X"] + $X;
     $Y = $Y - $TxtPos[$Align]["Y"] + $Y;

     if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
      {
       $C_ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
       imagettftext($this->Picture,$FontSize,$Angle,$X+$this->ShadowX,$Y+$this->ShadowY,$C_ShadowColor,$FontName,$Text);
      }

     $C_TextColor = $this->AllocateColor($this->Picture,$R,$G,$B,$Alpha);
     imagettftext($this->Picture,$FontSize,$Angle,$X,$Y,$C_TextColor,$FontName,$Text);

     $this->Shadow = $Shadow;

     return($TxtPos);
    }

   /* Draw a gradient within a defined area */
   function drawGradientArea($X1,$Y1,$X2,$Y2,$Direction,$Format="")
    {
     $StartR	= isset($Format["StartR"]) ? $Format["StartR"] : 90;
     $StartG	= isset($Format["StartG"]) ? $Format["StartG"] : 90;
     $StartB	= isset($Format["StartB"]) ? $Format["StartB"] : 90;
     $EndR	= isset($Format["EndR"]) ? $Format["EndR"] : 0;
     $EndG	= isset($Format["EndG"]) ? $Format["EndG"] : 0;
     $EndB	= isset($Format["EndB"]) ? $Format["EndB"] : 0;
     $Alpha	= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $Levels	= isset($Format["Levels"]) ? $Format["Levels"] : NULL;

     $Shadow = $this->Shadow;
     $this->Shadow = FALSE;

     if ( $StartR == $EndR && $StartG == $EndG && $StartB == $EndB )
      {
       $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,array("R"=>$StartR,"G"=>$StartG,"B"=>$StartB,"Alpha"=>$Alpha));
       return(0);
      }

     if ( $Levels != NULL )
      { $EndR=$StartR+$Levels; $EndG=$StartG+$Levels; $EndB=$StartB+$Levels; }

     if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
     if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }

     if ( $Direction == DIRECTION_VERTICAL )   { $Width = abs($Y2-$Y1); }
     if ( $Direction == DIRECTION_HORIZONTAL ) { $Width = abs($X2-$X1); }

     $Step     = max(abs($EndR-$StartR),abs($EndG-$StartG),abs($EndB-$StartB));
     $StepSize = $Width/$Step;
     $RStep    = ($EndR-$StartR)/$Step;
     $GStep    = ($EndG-$StartG)/$Step;
     $BStep    = ($EndB-$StartB)/$Step;

     $R=$StartR;$G=$StartG;$B=$StartB;
     switch($Direction)
      {
       case DIRECTION_VERTICAL:
        $StartY = $Y1; $EndY = floor($Y2)+1; $LastY2 = $StartY;
        for($i=0;$i<=$Step;$i++)
         {
          $Y2 = floor($StartY + ($i * $StepSize));

          if ($Y2 > $EndY) { $Y2 = $EndY; }
          if (($Y1 != $Y2 && $Y1 < $Y2) || $Y2 == $EndY)
           {
            $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
            $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color);
            $LastY2 = max($LastY2,$Y2);
            $Y1 = $Y2+1;
           }
          $R = $R + $RStep; $G = $G + $GStep; $B = $B + $BStep;
         }
        if ( $LastY2 < $EndY && isset($Color)) { for ($i=$LastY2+1;$i<=$EndY;$i++) { $this->drawLine($X1,$i,$X2,$i,$Color); } }
        break;

       case DIRECTION_HORIZONTAL:
        $StartX = $X1; $EndX = $X2;
        for($i=0;$i<=$Step;$i++)
         {
          $X2 = floor($StartX + ($i * $StepSize));

          if ($X2 > $EndX) { $X2 = $EndX; }
          if (($X1 != $X2 && $X1 < $X2) || $X2 == $EndX)
           {
            $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
            $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color);
            $X1 = $X2+1;
           }
          $R = $R + $RStep; $G = $G + $GStep; $B = $B + $BStep; 
         }
        if ( $X2 < $EndX && isset($Color)) { $this->drawFilledRectangle($X2,$Y1,$EndX,$Y2,$Color); }
        break;
      }

     $this->Shadow = $Shadow;

    }

   /* Draw an aliased pixel */
   function drawAntialiasPixel($X,$Y,$Format="")
    {
     $R     = isset($Format["R"]) ? $Format["R"] : 0;
     $G     = isset($Format["G"]) ? $Format["G"] : 0;
     $B     = isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;

     if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
      return(-1);

     if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
     if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
     if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }

     if ( !$this->Antialias )
      {
       if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
        {
         $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
         imagesetpixel($this->Picture,$X+$this->ShadowX,$Y+$this->ShadowY,$ShadowColor);
        }

       $PlotColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
       imagesetpixel($this->Picture,$X,$Y,$PlotColor);

       return(0);
      }

     $Plot = "";
     $Xi   = floor($X);
     $Yi   = floor($Y);

     if ( $Xi == $X && $Yi == $Y)
      {
       if ( $Alpha == 100 )
        $this->drawAlphaPixel($X,$Y,100,$R,$G,$B);
       else
        $this->drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B);
      }
     else
      {
       $Alpha1 = (((1 - ($X - floor($X))) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
       if ( $Alpha1 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi,$Alpha1,$R,$G,$B); }

       $Alpha2 = ((($X - floor($X)) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
       if ( $Alpha2 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi,$Alpha2,$R,$G,$B); }

       $Alpha3 = (((1 - ($X - floor($X))) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
       if ( $Alpha3 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi+1,$Alpha3,$R,$G,$B); }

       $Alpha4 = ((($X - floor($X)) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
       if ( $Alpha4 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi+1,$Alpha4,$R,$G,$B); }
      }
    }

   /* Draw a semi-transparent pixel */
   function drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B)
    {
     if ( isset($this->Mask[$X])) { if ( isset($this->Mask[$X][$Y]) ) { return(0); } }

     if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
      return(-1);

     if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
     if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
     if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }

     if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
      {
       $AlphaFactor = floor(($Alpha / 100) * $this->Shadowa);
       $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$AlphaFactor);
       imagesetpixel($this->Picture,$X+$this->ShadowX,$Y+$this->ShadowY,$ShadowColor);
      }

     $C_Aliased = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
     imagesetpixel($this->Picture,$X,$Y,$C_Aliased);
    }

   /* Convert apha to base 10 */
   function convertAlpha($AlphaValue)
    { return((127/100)*(100-$AlphaValue)); }

   /* Allocate a color with transparency */
   function allocateColor($Picture,$R,$G,$B,$Alpha=100)
    {
     if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
     if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
     if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
     if ( $Alpha < 0 )  { $Alpha = 0; }
     if ( $Alpha > 100) { $Alpha = 100; }

     $Alpha = $this->convertAlpha($Alpha);
     return(imagecolorallocatealpha($Picture,$R,$G,$B,$Alpha));
    }

   /* Load a PNG file and draw it over the chart */
   function drawFromPNG($X,$Y,$FileName)
    { $this->drawFromPicture(1,$FileName,$X,$Y); }

   /* Load a GIF file and draw it over the chart */
   function drawFromGIF($X,$Y,$FileName)
    { $this->drawFromPicture(2,$FileName,$X,$Y); }

   /* Load a JPEG file and draw it over the chart */
   function drawFromJPG($X,$Y,$FileName)
    { $this->drawFromPicture(3,$FileName,$X,$Y); }

   function getPicInfo($FileName)
    {
     $Infos  = getimagesize($FileName);
     $Width  = $Infos[0];
     $Height = $Infos[1];
     $Type   = $Infos["mime"];

     if ( $Type == "image/png") { $Type = 1; }
     if ( $Type == "image/gif") { $Type = 2; }
     if ( $Type == "image/jpeg ") { $Type = 3; }

     return(array($Width,$Height,$Type));
    }

   /* Generic loader function for external pictures */
   function drawFromPicture($PicType,$FileName,$X,$Y)
    {
     if ( file_exists($FileName))
      {
       list($Width,$Height) = $this->getPicInfo($FileName);

       if ( $PicType == 1 )
        { $Raster = imagecreatefrompng($FileName); }
       elseif ( $PicType == 2 )
        { $Raster = imagecreatefromgif($FileName); }
       elseif ( $PicType == 3 )
        { $Raster = imagecreatefromjpeg($FileName); }
       else
        { return(0); }


       $RestoreShadow = $this->Shadow;
       if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
        {
         $this->Shadow = FALSE;
         if ( $PicType == 3 )
          $this->drawFilledRectangle($X+$this->ShadowX,$Y+$this->ShadowY,$X+$Width+$this->ShadowX,$Y+$Height+$this->ShadowY,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
         else
          {
           $TranparentID = imagecolortransparent($Raster);
           for ($Xc=0;$Xc<=$Width-1;$Xc++)
            {
             for ($Yc=0;$Yc<=$Height-1;$Yc++)
              {
               $RGBa   = imagecolorat($Raster,$Xc,$Yc);
               $Values = imagecolorsforindex($Raster,$RGBa);
               if ( $Values["alpha"] < 120 )
                {
                 $AlphaFactor = floor(($this->Shadowa / 100) * ((100 / 127) * (127-$Values["alpha"])));
                 $this->drawAlphaPixel($X+$Xc+$this->ShadowX,$Y+$Yc+$this->ShadowY,$AlphaFactor,$this->ShadowR,$this->ShadowG,$this->ShadowB);
                }
              }
            }
          }
        }
       $this->Shadow = $RestoreShadow;

       imagecopy($this->Picture,$Raster,$X,$Y,0,0,$Width,$Height);
       imagedestroy($Raster);
      }
    }

   /* Draw an arrow */
   function drawArrow($X1,$Y1,$X2,$Y2,$Format="")
    {
     $FillR	= isset($Format["FillR"]) ? $Format["FillR"] : 0;
     $FillG	= isset($Format["FillG"]) ? $Format["FillG"] : 0;
     $FillB	= isset($Format["FillB"]) ? $Format["FillB"] : 0;
     $BorderR	= isset($Format["BorderR"]) ? $Format["BorderR"] : $FillR;
     $BorderG	= isset($Format["BorderG"]) ? $Format["BorderG"] : $FillG;
     $BorderB	= isset($Format["BorderB"]) ? $Format["BorderB"] : $FillB;
     $Alpha	= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $Size	= isset($Format["Size"]) ? $Format["Size"] : 10;
     $Ratio	= isset($Format["Ratio"]) ? $Format["Ratio"] : .5;
     $TwoHeads	= isset($Format["TwoHeads"]) ? $Format["TwoHeads"] : FALSE;
     $Ticks	= isset($Format["Ticks"]) ? $Format["Ticks"] : FALSE;

     /* Calculate the line angle */
     $Angle = $this->getAngle($X1,$Y1,$X2,$Y2);

     /* Override Shadow support, this will be managed internally */
     $RestoreShadow = $this->Shadow;
     if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
      {
       $this->Shadow = FALSE;
       $this->drawArrow($X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,array("FillR"=>$this->ShadowR,"FillG"=>$this->ShadowG,"FillB"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Size"=>$Size,"Ratio"=>$Ratio,"TwoHeads"=>$TwoHeads,"Ticks"=>$Ticks));
      }

     /* Draw the 1st Head */
     $TailX = cos(($Angle-180)*PI/180)*$Size+$X2;
     $TailY = sin(($Angle-180)*PI/180)*$Size+$Y2;

     $Points	= "";
     $Points[]  = $X2; $Points[]  = $Y2;
     $Points[]	= cos(($Angle-90)*PI/180)*$Size*$Ratio+$TailX; $Points[] = sin(($Angle-90)*PI/180)*$Size*$Ratio+$TailY;
     $Points[]	= cos(($Angle-270)*PI/180)*$Size*$Ratio+$TailX; $Points[] = sin(($Angle-270)*PI/180)*$Size*$Ratio+$TailY;
     $Points[]  = $X2; $Points[]  = $Y2;

     /* Visual correction */
     if ($Angle == 180 || $Angle == 360 ) { $Points[4] = $Points[2]; }
     if ($Angle == 90 || $Angle == 270 ) { $Points[5] = $Points[3]; }

     $ArrowColor = $this->allocateColor($this->Picture,$FillR,$FillG,$FillB,$Alpha);
     ImageFilledPolygon($this->Picture,$Points,4,$ArrowColor);

     $this->drawLine($Points[0],$Points[1],$Points[2],$Points[3],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
     $this->drawLine($Points[2],$Points[3],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
     $this->drawLine($Points[0],$Points[1],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));

     /* Draw the second head */
     if ( $TwoHeads )
      {
       $Angle = $this->getAngle($X2,$Y2,$X1,$Y1);

       $TailX2 = cos(($Angle-180)*PI/180)*$Size+$X1;
       $TailY2 = sin(($Angle-180)*PI/180)*$Size+$Y1;

       $Points   = "";
       $Points[] = $X1; $Points[]  = $Y1;
       $Points[] = cos(($Angle-90)*PI/180)*$Size*$Ratio+$TailX2; $Points[] = sin(($Angle-90)*PI/180)*$Size*$Ratio+$TailY2;
       $Points[] = cos(($Angle-270)*PI/180)*$Size*$Ratio+$TailX2; $Points[] = sin(($Angle-270)*PI/180)*$Size*$Ratio+$TailY2;
       $Points[] = $X1; $Points[]  = $Y1;

       /* Visual correction */
       if ($Angle == 180 || $Angle == 360 ) { $Points[4] = $Points[2]; }
       if ($Angle == 90 || $Angle == 270 ) { $Points[5] = $Points[3]; }

       $ArrowColor = $this->allocateColor($this->Picture,$FillR,$FillG,$FillB,$Alpha);
       ImageFilledPolygon($this->Picture,$Points,4,$ArrowColor);

       $this->drawLine($Points[0],$Points[1],$Points[2],$Points[3],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
       $this->drawLine($Points[2],$Points[3],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
       $this->drawLine($Points[0],$Points[1],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));

       $this->drawLine($TailX,$TailY,$TailX2,$TailY2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
      }
     else
      $this->drawLine($X1,$Y1,$TailX,$TailY,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));

     /* Re-enable shadows */
     $this->Shadow = $RestoreShadow;
    }

   /* Draw a label with associated arrow */
   function drawArrowLabel($X1,$Y1,$Text,$Format="")
    {
     $FillR    = isset($Format["FillR"]) ? $Format["FillR"] : 0;
     $FillG    = isset($Format["FillG"]) ? $Format["FillG"] : 0;
     $FillB    = isset($Format["FillB"]) ? $Format["FillB"] : 0;
     $BorderR  = isset($Format["BorderR"]) ? $Format["BorderR"] : $FillR;
     $BorderG  = isset($Format["BorderG"]) ? $Format["BorderG"] : $FillG;
     $BorderB  = isset($Format["BorderB"]) ? $Format["BorderB"] : $FillB;
     $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
     $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
     $Alpha    = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $Length   = isset($Format["Length"]) ? $Format["Length"] : 50;
     $Angle    = isset($Format["Angle"]) ? $Format["Angle"] : 315;
     $Size     = isset($Format["Size"]) ? $Format["Size"] : 10;
     $Position = isset($Format["Position"]) ? $Format["Position"] : POSITION_TOP;
     $RoundPos = isset($Format["RoundPos"]) ? $Format["RoundPos"] : FALSE;
     $Ticks    = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;

     $Angle = $Angle % 360;

     $X2 = sin(($Angle+180)*PI/180)*$Length+$X1;
     $Y2 = cos(($Angle+180)*PI/180)*$Length+$Y1;

     if ( $RoundPos && $Angle > 0 && $Angle < 180 ) { $Y2 = ceil($Y2); }
     if ( $RoundPos && $Angle > 180 ) { $Y2 = floor($Y2); }

     $this->drawArrow($X2,$Y2,$X1,$Y1,$Format);

     $Size	= imagettfbbox($FontSize,0,$FontName,$Text);
     $TxtWidth	= max(abs($Size[2]-$Size[0]),abs($Size[0]-$Size[6]));
     $TxtHeight	= max(abs($Size[1]-$Size[7]),abs($Size[3]-$Size[1]));

     if ( $Angle > 0 && $Angle < 180 )
      {
       $this->drawLine($X2,$Y2,$X2-$TxtWidth,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
       if ( $Position == POSITION_TOP )
        $this->drawText($X2,$Y2-2,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_BOTTOMRIGHT));
       else
        $this->drawText($X2,$Y2+4,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_TOPRIGHT));
      }
     else
      {
       $this->drawLine($X2,$Y2,$X2+$TxtWidth,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
       if ( $Position == POSITION_TOP )
        $this->drawText($X2,$Y2-2,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
       else
        $this->drawText($X2,$Y2+4,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_TOPLEFT));
      }
    }

   /* Draw a progress bar filled with specified % */
   function drawProgress($X,$Y,$Percent,$Format="")
    {
     if ( $Percent > 100 ) { $Percent = 100; }
     if ( $Percent < 0 ) { $Percent = 0; }

     $Width	= isset($Format["Width"]) ? $Format["Width"] : 200;
     $Height	= isset($Format["Height"]) ? $Format["Height"] : 20;
     $Orientation = isset($Format["Orientation"]) ? $Format["Orientation"] : ORIENTATION_HORIZONTAL;
     $ShowLabel = isset($Format["ShowLabel"]) ? $Format["ShowLabel"] : FALSE;
     $LabelPos	= isset($Format["LabelPos"]) ? $Format["LabelPos"] : LABEL_POS_INSIDE;
     $Margin    = isset($Format["Margin"]) ? $Format["Margin"] : 10;
     $R		= isset($Format["R"]) ? $Format["R"] : 130;
     $G		= isset($Format["G"]) ? $Format["G"] : 130;
     $B		= isset($Format["B"]) ? $Format["B"] : 130;
     $RFade	= isset($Format["RFade"]) ? $Format["RFade"] : -1;
     $GFade	= isset($Format["GFade"]) ? $Format["GFade"] : -1;
     $BFade	= isset($Format["BFade"]) ? $Format["BFade"] : -1;
     $BorderR	= isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
     $BorderG	= isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
     $BorderB	= isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
     $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 0;
     $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 0;
     $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 0;
     $BoxBackR	= isset($Format["BoxBackR"]) ? $Format["BoxBackR"] : 255;
     $BoxBackG	= isset($Format["BoxBackG"]) ? $Format["BoxBackG"] : 255;
     $BoxBackB	= isset($Format["BoxBackB"]) ? $Format["BoxBackB"] : 255;
     $Alpha	= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
     $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : NULL;
     $NoAngle	= isset($Format["NoAngle"]) ? $Format["NoAngle"] : FALSE;

     if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
      {
       $RFade = (($RFade-$R)/100)*$Percent+$R;
       $GFade = (($GFade-$G)/100)*$Percent+$G;
       $BFade = (($BFade-$B)/100)*$Percent+$B;
      }

     if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
     if ( $BoxSurrounding != NULL ) { $BoxBorderR = $BoxBackR + $Surrounding; $BoxBorderG = $BoxBackG + $Surrounding; $BoxBorderB = $BoxBackB + $Surrounding; }

     if ( $Orientation == ORIENTATION_VERTICAL )
      {
       $InnerHeight = (($Height-2)/100)*$Percent;
       $this->drawFilledRectangle($X,$Y,$X+$Width,$Y-$Height,array("R"=>$BoxBackR,"G"=>$BoxBackG,"B"=>$BoxBackB,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"NoAngle"=>$NoAngle));

       $RestoreShadow = $this->Shadow; $this->Shadow  = FALSE;
       if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
        {
         $GradientOptions = array("StartR"=>$RFade,"StartG"=>$GFade,"StartB"=>$BFade,"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
         $this->drawGradientArea($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,DIRECTION_VERTICAL,$GradientOptions);

         if ( $Surrounding )
          $this->drawRectangle($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,array("R"=>255,"G"=>255,"B"=>255,"Alpha"=>$Surrounding));
        }
       else
        $this->drawFilledRectangle($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));

       $this->Shadow = $RestoreShadow;

       if ( $ShowLabel && $LabelPos == LABEL_POS_BOTTOM )	{ $this->drawText($X+($Width/2),$Y+$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_TOPMIDDLE)); }
       if ( $ShowLabel && $LabelPos == LABEL_POS_TOP )		{ $this->drawText($X+($Width/2),$Y-$Height-$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); }
       if ( $ShowLabel && $LabelPos == LABEL_POS_INSIDE )	{ $this->drawText($X+($Width/2),$Y-$InnerHeight-$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT,"Angle"=>90)); }
       if ( $ShowLabel && $LabelPos == LABEL_POS_CENTER )	{ $this->drawText($X+($Width/2),$Y-($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"Angle"=>90)); }
      }
     else
      {
       if ( $Percent == 100 )
        $InnerWidth = $Width-1;
       else
        $InnerWidth = (($Width-2)/100)*$Percent;

       $this->drawFilledRectangle($X,$Y,$X+$Width,$Y+$Height,array("R"=>$BoxBackR,"G"=>$BoxBackG,"B"=>$BoxBackB,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"NoAngle"=>$NoAngle));

       $RestoreShadow = $this->Shadow; $this->Shadow  = FALSE;
       if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
        {
         $GradientOptions = array("StartR"=>$R,"StartG"=>$G,"StartB"=>$B,"EndR"=>$RFade,"EndG"=>$GFade,"EndB"=>$BFade);
         $this->drawGradientArea($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,DIRECTION_HORIZONTAL,$GradientOptions);

         if ( $Surrounding )
          $this->drawRectangle($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,array("R"=>255,"G"=>255,"B"=>255,"Alpha"=>$Surrounding));
        }
       else
        $this->drawFilledRectangle($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
 
       $this->Shadow = $RestoreShadow;

       if ( $ShowLabel && $LabelPos == LABEL_POS_LEFT )		{ $this->drawText($X-$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); }
       if ( $ShowLabel && $LabelPos == LABEL_POS_RIGHT )	{ $this->drawText($X+$Width+$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
       if ( $ShowLabel && $LabelPos == LABEL_POS_CENTER )	{ $this->drawText($X+($Width/2),$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE)); }
       if ( $ShowLabel && $LabelPos == LABEL_POS_INSIDE )	{ $this->drawText($X+$InnerWidth+$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
      }
    }

   /* Get the legend box size */
   function getLegendSize($Format="")
    {
     $FontName		= isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
     $FontSize		= isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
     $BoxSize		= isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5;
     $Margin		= isset($Format["Margin"]) ? $Format["Margin"] : 5;
     $Style		= isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
     $Mode		= isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
     $BoxWidth		= isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
     $BoxHeight		= isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
     $IconAreaWidth	= isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
     $IconAreaHeight	= isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
     $XSpacing		= isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;

     $Data = $this->DataSet->getData();

     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && isset($Serie["Picture"]))
        {
         list($PicWidth,$PicHeight) = $this->getPicInfo($Serie["Picture"]);
         if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
         if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
        }
      }

     $YStep = max($this->FontSize,$IconAreaHeight) + 5;
     $XStep = $IconAreaWidth + 5;
     $XStep = $XSpacing;

     $X=100; $Y=100;

     $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         if ( $Mode == LEGEND_VERTICAL )
          {
           $BoxArray = $this->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Serie["Description"]);

           if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
           if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
           if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }

           $Lines = preg_split("/\n/",$Serie["Description"]);
           $vY = $vY + max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
          }
         elseif ( $Mode == LEGEND_HORIZONTAL )
          {
           $Lines = preg_split("/\n/",$Serie["Description"]);
           $Width = "";
           foreach($Lines as $Key => $Value)
            {
             $BoxArray = $this->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);

             if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
             if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
             if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }

             $Width[] = $BoxArray[1]["X"];
            }

           $vX=max($Width)+$XStep;
          }
        }
      }
     $vY=$vY-$YStep; $vX=$vX-$XStep;

     $TopOffset  = $Y - $Boundaries["T"];
     if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }

     $Width  = ($Boundaries["R"]+$Margin) - ($Boundaries["L"]-$Margin);
     $Height = ($Boundaries["B"]+$Margin) - ($Boundaries["T"]-$Margin);

     return(array("Width"=>$Width,"Height"=>$Height));
    }

   /* Draw the legend of the active series */
   function drawLegend($X,$Y,$Format="")
    {
     $Family	= isset($Format["Family"]) ? $Format["Family"] : LEGEND_FAMILY_BOX;
     $FontName	= isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
     $FontSize	= isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
     $FontR	= isset($Format["FontR"]) ? $Format["FontR"] : $this->FontColorR;
     $FontG	= isset($Format["FontG"]) ? $Format["FontG"] : $this->FontColorG;
     $FontB	= isset($Format["FontB"]) ? $Format["FontB"] : $this->FontColorB;
     $BoxWidth	= isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
     $BoxHeight	= isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
     $IconAreaWidth	= isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
     $IconAreaHeight	= isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
     $XSpacing	= isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
     $Margin	= isset($Format["Margin"]) ? $Format["Margin"] : 5;
     $R		= isset($Format["R"]) ? $Format["R"] : 200;
     $G		= isset($Format["G"]) ? $Format["G"] : 200;
     $B		= isset($Format["B"]) ? $Format["B"] : 200;
     $Alpha	= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $BorderR	= isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
     $BorderG	= isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
     $BorderB	= isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
     $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
     $Style	= isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
     $Mode	= isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;

     if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }

     $Data = $this->DataSet->getData();

     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && isset($Serie["Picture"]))
        {
         list($PicWidth,$PicHeight) = $this->getPicInfo($Serie["Picture"]);
         if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
         if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
        }
      }


     $YStep = max($this->FontSize,$IconAreaHeight) + 5;
     $XStep = $IconAreaWidth + 5;
     $XStep = $XSpacing;

     $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         if ( $Mode == LEGEND_VERTICAL )
          {
           $BoxArray = $this->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Serie["Description"]);

           if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
           if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
           if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }

           $Lines = preg_split("/\n/",$Serie["Description"]);
           $vY = $vY + max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
          }
         elseif ( $Mode == LEGEND_HORIZONTAL )
          {
           $Lines = preg_split("/\n/",$Serie["Description"]);
           $Width = "";
           foreach($Lines as $Key => $Value)
            {
             $BoxArray = $this->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);

             if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
             if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
             if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }

             $Width[] = $BoxArray[1]["X"];
            }

           $vX=max($Width)+$XStep;
          }
        }
      }
     $vY=$vY-$YStep; $vX=$vX-$XStep;

     $TopOffset  = $Y - $Boundaries["T"];
     if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }

     if ( $Style == LEGEND_ROUND )
      $this->drawRoundedFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
     elseif ( $Style == LEGEND_BOX )
      $this->drawFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));

     $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"];
         $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];

         if ( isset($Serie["Picture"]) )
          {
           $Picture = $Serie["Picture"];
           list($PicWidth,$PicHeight) = $this->getPicInfo($Picture);
           $PicX = $X+$IconAreaWidth/2; $PicY = $Y+$IconAreaHeight/2; 

           $this->drawFromPNG($PicX-$PicWidth/2,$PicY-$PicHeight/2,$Picture);
          }
         else
          {
           if ( $Family == LEGEND_FAMILY_BOX )
            {
             if ( $BoxWidth != $IconAreaWidth ) { $XOffset = floor(($IconAreaWidth-$BoxWidth)/2); } else { $XOffset = 0; }
             if ( $BoxHeight != $IconAreaHeight ) { $YOffset = floor(($IconAreaHeight-$BoxHeight)/2); } else { $YOffset = 0; }

             $this->drawFilledRectangle($X+1+$XOffset,$Y+1+$YOffset,$X+$BoxWidth+$XOffset+1,$Y+$BoxHeight+1+$YOffset,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
             $this->drawFilledRectangle($X+$XOffset,$Y+$YOffset,$X+$BoxWidth+$XOffset,$Y+$BoxHeight+$YOffset,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
            }
           elseif ( $Family == LEGEND_FAMILY_CIRCLE )
            {
             $this->drawFilledCircle($X+1+$IconAreaWidth/2,$Y+1+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
             $this->drawFilledCircle($X+$IconAreaWidth/2,$Y+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
            }
           elseif ( $Family == LEGEND_FAMILY_LINE )
            {
             $this->drawLine($X+1,$Y+1+$IconAreaHeight/2,$X+1+$IconAreaWidth,$Y+1+$IconAreaHeight/2,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20,"Ticks"=>$Ticks,"Weight"=>$Weight));
             $this->drawLine($X,$Y+$IconAreaHeight/2,$X+$IconAreaWidth,$Y+$IconAreaHeight/2,array("R"=>$R,"G"=>$G,"B"=>$B,"Ticks"=>$Ticks,"Weight"=>$Weight));
            }
          }

         if ( $Mode == LEGEND_VERTICAL )
          {
           $Lines = preg_split("/\n/",$Serie["Description"]);
           foreach($Lines as $Key => $Value)
            $this->drawText($X+$IconAreaWidth+4,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));

           $Y=$Y+max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
          }
         elseif ( $Mode == LEGEND_HORIZONTAL )
          {
           $Lines = preg_split("/\n/",$Serie["Description"]);
           $Width = "";
           foreach($Lines as $Key => $Value)
            {
             $BoxArray = $this->drawText($X+$IconAreaWidth+4,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));
             $Width[] = $BoxArray[1]["X"];
            }
           $X=max($Width)+2+$XStep;
          }
        }
      }


     $this->Shadow = $RestoreShadow;
    }

   function drawScale($Format="")
    {
     $Pos		= isset($Format["Pos"]) ? $Format["Pos"] : SCALE_POS_LEFTRIGHT;
     $Floating		= isset($Format["Floating"]) ? $Format["Floating"] : FALSE;
     $Mode		= isset($Format["Mode"]) ? $Format["Mode"] : SCALE_MODE_FLOATING;
     $MinDivHeight	= isset($Format["MinDivHeight"]) ? $Format["MinDivHeight"] : 20;
     $Factors		= isset($Format["Factors"]) ? $Format["Factors"] : array(1,2,5);
     $ManualScale	= isset($Format["ManualScale"]) ? $Format["ManualScale"] : array("0"=>array("Min"=>-100,"Max"=>100));
     $XMargin		= isset($Format["XMargin"]) ? $Format["XMargin"] : AUTO;
     $YMargin		= isset($Format["YMargin"]) ? $Format["YMargin"] : 0;
     $ScaleSpacing	= isset($Format["ScaleSpacing"]) ? $Format["ScaleSpacing"] : 15;
     $InnerTickWidth	= isset($Format["InnerTickWidth"]) ? $Format["InnerTickWidth"] : 2;
     $OuterTickWidth	= isset($Format["OuterTickWidth"]) ? $Format["OuterTickWidth"] : 2;
     $DrawXLines	= isset($Format["DrawXLines"]) ? $Format["DrawXLines"] : TRUE;
     $DrawYLines	= isset($Format["DrawYLines"]) ? $Format["DrawYLines"] : ALL;
     $GridTicks		= isset($Format["GridTicks"]) ? $Format["GridTicks"] : 4;
     $GridR		= isset($Format["GridR"]) ? $Format["GridR"] : 255;
     $GridG		= isset($Format["GridG"]) ? $Format["GridG"] : 255;
     $GridB		= isset($Format["GridB"]) ? $Format["GridB"] : 255;
     $GridAlpha		= isset($Format["GridAlpha"]) ? $Format["GridAlpha"] : 40;
     $AxisRo		= isset($Format["AxisR"]) ? $Format["AxisR"] : 0;
     $AxisGo		= isset($Format["AxisG"]) ? $Format["AxisG"] : 0;
     $AxisBo		= isset($Format["AxisB"]) ? $Format["AxisB"] : 0;
     $AxisAlpha		= isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 100;
     $TickRo		= isset($Format["TickR"]) ? $Format["TickR"] : 0;
     $TickGo		= isset($Format["TickG"]) ? $Format["TickG"] : 0;
     $TickBo		= isset($Format["TickB"]) ? $Format["TickB"] : 0;
     $TickAlpha		= isset($Format["TickAlpha"]) ? $Format["TickAlpha"] : 100;
     $DrawSubTicks	= isset($Format["DrawSubTicks"]) ? $Format["DrawSubTicks"] : FALSE;
     $InnerSubTickWidth	= isset($Format["InnerSubTickWidth"]) ? $Format["InnerSubTickWidth"] : 0;
     $OuterSubTickWidth	= isset($Format["OuterSubTickWidth"]) ? $Format["OuterSubTickWidth"] : 2;
     $SubTickR		= isset($Format["SubTickR"]) ? $Format["SubTickR"] : 255;
     $SubTickG		= isset($Format["SubTickG"]) ? $Format["SubTickG"] : 0;
     $SubTickB		= isset($Format["SubTickB"]) ? $Format["SubTickB"] : 0;
     $SubTickAlpha	= isset($Format["SubTickAlpha"]) ? $Format["SubTickAlpha"] : 100;
     $AutoAxisLabels	= isset($Format["AutoAxisLabels"]) ? $Format["AutoAxisLabels"] : TRUE;
     $XReleasePercent	= isset($Format["XReleasePercent"]) ? $Format["XReleasePercent"] : 1;
     $DrawArrows	= isset($Format["DrawArrows"]) ? $Format["DrawArrows"] : FALSE;
     $ArrowSize         = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 8;
     $CycleBackground	= isset($Format["CycleBackground"]) ? $Format["CycleBackground"] : FALSE;
     $BackgroundR1	= isset($Format["BackgroundR1"]) ? $Format["BackgroundR1"] : 255;
     $BackgroundG1	= isset($Format["BackgroundG1"]) ? $Format["BackgroundG1"] : 255;
     $BackgroundB1	= isset($Format["BackgroundB1"]) ? $Format["BackgroundB1"] : 255;
     $BackgroundAlpha1	= isset($Format["BackgroundAlpha1"]) ? $Format["BackgroundAlpha1"] : 20;
     $BackgroundR2	= isset($Format["BackgroundR2"]) ? $Format["BackgroundR2"] : 230;
     $BackgroundG2	= isset($Format["BackgroundG2"]) ? $Format["BackgroundG2"] : 230;
     $BackgroundB2	= isset($Format["BackgroundB2"]) ? $Format["BackgroundB2"] : 230;
     $BackgroundAlpha2	= isset($Format["BackgroundAlpha2"]) ? $Format["BackgroundAlpha2"] : 20;
     $LabelingMethod	= isset($Format["LabelingMethod"]) ? $Format["LabelingMethod"] : LABELING_ALL;
     $LabelSkip		= isset($Format["LabelSkip"]) ? $Format["LabelSkip"] : 0;
     $LabelRotation	= isset($Format["LabelRotation"]) ? $Format["LabelRotation"] : 0;
     $SkippedAxisTicks	= isset($Format["SkippedAxisTicks"]) ? $Format["SkippedAxisTicks"] : $GridTicks+2;
     $SkippedAxisR	= isset($Format["SkippedAxisR"]) ? $Format["SkippedAxisR"] : $GridR;
     $SkippedAxisG	= isset($Format["SkippedAxisG"]) ? $Format["SkippedAxisG"] : $GridG;
     $SkippedAxisB	= isset($Format["SkippedAxisB"]) ? $Format["SkippedAxisB"] : $GridB;
     $SkippedAxisAlpha	= isset($Format["SkippedAxisAlpha"]) ? $Format["SkippedAxisAlpha"] : $GridAlpha-30;
     $SkippedTickR	= isset($Format["SkippedTickR"]) ? $Format["SkippedTickR"] : $TickRo;
     $SkippedTickG	= isset($Format["SkippedTickG"]) ? $Format["SkippedTickG"] : $TickGo;
     $SkippedTickB	= isset($Format["SkippedTicksB"]) ? $Format["SkippedTickB"] : $TickBo;
     $SkippedTickAlpha	= isset($Format["SkippedTickAlpha"]) ? $Format["SkippedTickAlpha"] : $TickAlpha-80;
     $SkippedInnerTickWidth	= isset($Format["SkippedInnerTickWidth"]) ? $Format["SkippedInnerTickWidth"] : 0;
     $SkippedOuterTickWidth	= isset($Format["SkippedOuterTickWidth"]) ? $Format["SkippedOuterTickWidth"] : 2;

     /* Floating scale require X & Y margins to be set manually */
     if ( $Floating && ( $XMargin == AUTO || $YMargin == 0 ) ) { $Floating = FALSE; }

     /* Skip a NOTICE event in case of an empty array */
     if ( $DrawYLines == NONE || $DrawYLines == FALSE ) { $DrawYLines = array("zarma"=>"31"); }

     /* Define the color for the skipped elements */
     $SkippedAxisColor = array("R"=>$SkippedAxisR,"G"=>$SkippedAxisG,"B"=>$SkippedAxisB,"Alpha"=>$SkippedAxisAlpha,"Ticks"=>$SkippedAxisTicks);
     $SkippedTickColor = array("R"=>$SkippedTickR,"G"=>$SkippedTickG,"B"=>$SkippedTickB,"Alpha"=>$SkippedTickAlpha);

     $Data = $this->DataSet->getData();
     if ( isset($Data["Abscissa"]) ) { $Abscissa = $Data["Abscissa"]; } else { $Abscissa = NULL; }

     /* Unset the abscissa axis, needed if we display multiple charts on the same picture */
     if ( $Abscissa != NULL )
      {
       foreach($Data["Axis"] as $AxisID => $Parameters)
        { if ($Parameters["Identity"] == AXIS_X) { unset($Data["Axis"][$AxisID]); } }
      }

     /* Build the scale settings */
     $GotXAxis = FALSE;
     foreach($Data["Axis"] as $AxisID => $AxisParameter)
      {
       if ( $AxisParameter["Identity"] == AXIS_X ) { $GotXAxis = TRUE; }

       if ( $Pos == SCALE_POS_LEFTRIGHT && $AxisParameter["Identity"] == AXIS_Y)
        { $Height = $this->GraphAreaY2-$this->GraphAreaY1 - $YMargin*2; }
       elseif ( $Pos == SCALE_POS_LEFTRIGHT && $AxisParameter["Identity"] == AXIS_X)
        { $Height = $this->GraphAreaX2-$this->GraphAreaX1; }
       elseif ( $Pos == SCALE_POS_TOPBOTTOM && $AxisParameter["Identity"] == AXIS_Y)
        { $Height = $this->GraphAreaX2-$this->GraphAreaX1 - $YMargin*2;; }
       else
        { $Height = $this->GraphAreaY2-$this->GraphAreaY1; }

       $AxisMin = ABSOLUTE_MAX; $AxisMax = OUT_OF_SIGHT;
       if ( $Mode == SCALE_MODE_FLOATING || $Mode == SCALE_MODE_START0 )
        {
         foreach($Data["Series"] as $SerieID => $SerieParameter)
          {
           if ( $SerieParameter["Axis"] == $AxisID && $Data["Series"][$SerieID]["isDrawable"] && $Data["Abscissa"] != $SerieID)
            {
             $AxisMax = max($AxisMax,$Data["Series"][$SerieID]["Max"]);
             $AxisMin = min($AxisMin,$Data["Series"][$SerieID]["Min"]);
            }
          }
         $AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;

         $Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
         if ( $Mode == SCALE_MODE_START0 ) { $Data["Axis"][$AxisID]["Min"] = 0; }
        }
       elseif ( $Mode == SCALE_MODE_MANUAL )
        {
         if ( isset($ManualScale[$AxisID]["Min"]) && isset($ManualScale[$AxisID]["Max"]) )
          {
           $Data["Axis"][$AxisID]["Min"] = $ManualScale[$AxisID]["Min"];
           $Data["Axis"][$AxisID]["Max"] = $ManualScale[$AxisID]["Max"];
          }
         else
          { echo "Manual scale boundaries not set."; exit(); }
        }
       elseif ( $Mode == SCALE_MODE_ADDALL || $Mode == SCALE_MODE_ADDALL_START0 )
        {
         $Series = "";
         foreach($Data["Series"] as $SerieID => $SerieParameter)
          { if ( $SerieParameter["Axis"] == $AxisID && $SerieParameter["isDrawable"] && $Data["Abscissa"] != $SerieID ) { $Series[$SerieID] = count($Data["Series"][$SerieID]["Data"]); } }

         for ($ID=0;$ID<=max($Series)-1;$ID++)
          {
           $PointMin = 0; $PointMax = 0;
           foreach($Series as $SerieID => $ValuesCount )
            {
             if (isset($Data["Series"][$SerieID]["Data"][$ID]) && $Data["Series"][$SerieID]["Data"][$ID] != NULL )
              {
               $Value = $Data["Series"][$SerieID]["Data"][$ID];
               if ( $Value > 0 ) { $PointMax = $PointMax + $Value; } else { $PointMin = $PointMin + $Value; }
              }
            }
           $AxisMax = max($AxisMax,$PointMax);
           $AxisMin = min($AxisMin,$PointMin);
          }
         $AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;
         $Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
        }
       $MaxDivs = floor($Height/$MinDivHeight);

       if ( $Mode == SCALE_MODE_ADDALL_START0 ) { $Data["Axis"][$AxisID]["Min"] = 0; }

       $Scale   = $this->computeScale($Data["Axis"][$AxisID]["Min"],$Data["Axis"][$AxisID]["Max"],$MaxDivs,$Factors,$AxisID);

       $Data["Axis"][$AxisID]["Margin"]    = $AxisParameter["Identity"] == AXIS_X ? $XMargin : $YMargin;
       $Data["Axis"][$AxisID]["ScaleMin"]  = $Scale["XMin"];
       $Data["Axis"][$AxisID]["ScaleMax"]  = $Scale["XMax"];
       $Data["Axis"][$AxisID]["Rows"]      = $Scale["Rows"];
       $Data["Axis"][$AxisID]["RowHeight"] = $Scale["RowHeight"];

       if ( isset($Scale["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = $Scale["Format"]; }

       if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
       if ( !isset($Data["Axis"][$AxisID]["Format"]) )  { $Data["Axis"][$AxisID]["Format"] = NULL; }
       if ( !isset($Data["Axis"][$AxisID]["Unit"]) )    { $Data["Axis"][$AxisID]["Unit"] = NULL; }
      }

     /* Still no X axis */
     if ( $GotXAxis == FALSE )
      {
       if ( $Abscissa != NULL )
        {
         $Points = count($Data["Series"][$Abscissa]["Data"]);
         if ( $AutoAxisLabels )
          $AxisName = isset($Data["Series"][$Abscissa]["Description"]) ? $Data["Series"][$Abscissa]["Description"] : NULL;
         else
          $AxisName = NULL;
        }
       else
        {
         $Points = 0;
         $AxisName = isset($Data["XAxisName"]) ? $Data["XAxisName"] : NULL;
         foreach($Data["Series"] as $SerieID => $SerieParameter)
          { if ( $SerieParameter["isDrawable"] ) { $Points = max($Points,count($SerieParameter["Data"])); } }
        }

       $AxisID = count($Data["Axis"]);
       $Data["Axis"][$AxisID]["Identity"] = AXIS_X;
       if ( $Pos == SCALE_POS_LEFTRIGHT ) { $Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_BOTTOM; } else { $Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_LEFT; }
       if ( isset($Data["AbscissaName"]) ) { $Data["Axis"][$AxisID]["Name"] = $Data["AbscissaName"]; }
       if ( $XMargin == AUTO )
        {
         if ( $Pos == SCALE_POS_LEFTRIGHT )
          { $Height = $this->GraphAreaX2-$this->GraphAreaX1; }
         else
          { $Height = $this->GraphAreaY2-$this->GraphAreaY1; }

         if ( $Points == 1 )
          $Data["Axis"][$AxisID]["Margin"] = $Height / 2;
         else
          $Data["Axis"][$AxisID]["Margin"] = ($Height/$Points) / 2;
        }
       else
        { $Data["Axis"][$AxisID]["Margin"] = $XMargin; }
       $Data["Axis"][$AxisID]["Rows"] = $Points-1;
       if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
       if ( !isset($Data["Axis"][$AxisID]["Format"]) )  { $Data["Axis"][$AxisID]["Format"] = NULL; }
       if ( !isset($Data["Axis"][$AxisID]["Unit"]) )    { $Data["Axis"][$AxisID]["Unit"] = NULL; }
      }

     $this->DataSet->saveOrientation($Pos);
     $this->DataSet->saveAxisConfig($Data["Axis"]);
     $this->DataSet->saveYMargin($YMargin);

     $FontColorRo = $this->FontColorR; $FontColorGo = $this->FontColorG; $FontColorBo = $this->FontColorB;

     $AxisPos["L"] = $this->GraphAreaX1; $AxisPos["R"] = $this->GraphAreaX2; $AxisPos["T"] = $this->GraphAreaY1; $AxisPos["B"] = $this->GraphAreaY2;
     foreach($Data["Axis"] as $AxisID => $Parameters)
      {
       if ( isset($Parameters["Color"]) )
        {
         $AxisR = $Parameters["Color"]["R"]; $AxisG = $Parameters["Color"]["G"]; $AxisB = $Parameters["Color"]["B"];
         $TickR = $Parameters["Color"]["R"]; $TickG = $Parameters["Color"]["G"]; $TickB = $Parameters["Color"]["B"];
         $this->setFontProperties(array("R"=>$Parameters["Color"]["R"],"G"=>$Parameters["Color"]["G"],"B"=>$Parameters["Color"]["B"]));
        }
       else
        {
         $AxisR = $AxisRo; $AxisG = $AxisGo; $AxisB = $AxisBo;
         $TickR = $TickRo; $TickG = $TickGo; $TickB = $TickBo;
         $this->setFontProperties(array("R"=>$FontColorRo,"G"=>$FontColorGo,"B"=>$FontColorBo));
        }

       $LastValue = "w00t"; $ID = 1;
       if ( $Parameters["Identity"] == AXIS_X )
        {
         if ( $Pos == SCALE_POS_LEFTRIGHT )
          {
           if ( $Parameters["Position"] == AXIS_POSITION_BOTTOM )
            {
             if ( $LabelRotation == 0 )					{ $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $YLabelOffset = 2; }
             if ( $LabelRotation > 0 && $LabelRotation < 190 )		{ $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $YLabelOffset = 5; }
             if ( $LabelRotation == 180 )				{ $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $YLabelOffset = 5; }
             if ( $LabelRotation > 180 && $LabelRotation < 360 )	{ $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $YLabelOffset = 2; }

             if ( $Floating )
              { $FloatingOffset = $YMargin; $this->drawLine($this->GraphAreaX1+$Parameters["Margin"],$AxisPos["B"],$this->GraphAreaX2-$Parameters["Margin"],$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
             else
              { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["B"],$this->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }

             if ( $DrawArrows ) { $this->drawArrow($this->GraphAreaX2-$Parameters["Margin"],$AxisPos["B"],$this->GraphAreaX2+($ArrowSize*2),$AxisPos["B"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }

             $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;

             if ($Parameters["Rows"] == 0 ) { $Step  = $Width; } else { $Step  = $Width / ($Parameters["Rows"]); }
             
             $MaxBottom = $AxisPos["B"];
             for($i=0;$i<=$Parameters["Rows"];$i++)
              {
               $XPos  = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
               $YPos  = $AxisPos["B"];

               if ( $Abscissa != NULL )
                { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
               else
                {
                 if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
                  $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
                 else
                  $Value = $i;
                }

               $ID++; $Skipped = TRUE;
               if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) )
                {
                 $Bounds    = $this->drawText($XPos,$YPos+$OuterTickWidth+$YLabelOffset,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
                 $TxtBottom = $YPos+$OuterTickWidth+2+($Bounds[0]["Y"]-$Bounds[2]["Y"]);
                 $MaxBottom = max($MaxBottom,$TxtBottom);
                 $LastValue = $Value;
                 $Skipped   = FALSE;
                }

               if ( $Skipped )
                {
                 if ( $DrawXLines ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$SkippedAxisColor); }
                 if ( $SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0 ) { $this->drawLine($XPos,$YPos-$SkippedInnerTickWidth,$XPos,$YPos+$SkippedOuterTickWidth,$SkippedTickColor); }
                }
               else
                {
                 if ( $DrawXLines && ($XPos != $this->GraphAreaX1 && $XPos != $this->GraphAreaX2) ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
                 if ( $InnerTickWidth !=0 || $OuterTickWidth != 0 ) { $this->drawLine($XPos,$YPos-$InnerTickWidth,$XPos,$YPos+$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
                }

              }
             if ( isset($Parameters["Name"]) )
              {
               $YPos   = $MaxBottom+2;
               $XPos   = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
               $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
               $MaxBottom = $Bounds[0]["Y"];

               $this->DataSet->Data["GraphArea"]["Y2"] = $MaxBottom + $this->FontSize;
              }

             $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
            }
           elseif ( $Parameters["Position"] == AXIS_POSITION_TOP )
            {
             if ( $LabelRotation == 0 )					{ $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $YLabelOffset = 2; }
             if ( $LabelRotation > 0 && $LabelRotation < 190 )		{ $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $YLabelOffset = 2; }
             if ( $LabelRotation == 180 )				{ $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $YLabelOffset = 5; }
             if ( $LabelRotation > 180 && $LabelRotation < 360 )	{ $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $YLabelOffset = 5; }

             if ( $Floating )
              { $FloatingOffset = $YMargin; $this->drawLine($this->GraphAreaX1+$Parameters["Margin"],$AxisPos["T"],$this->GraphAreaX2-$Parameters["Margin"],$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
             else
              { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["T"],$this->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }

             if ( $DrawArrows ) { $this->drawArrow($this->GraphAreaX2-$Parameters["Margin"],$AxisPos["T"],$this->GraphAreaX2+($ArrowSize*2),$AxisPos["T"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }

             $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;

             if ($Parameters["Rows"] == 0 ) { $Step  = $Width; } else { $Step  = $Width / $Parameters["Rows"]; }
             
             $MinTop = $AxisPos["T"];
             for($i=0;$i<=$Parameters["Rows"];$i++)
              {
               $XPos  = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
               $YPos  = $AxisPos["T"];

               if ( $Abscissa != NULL )
                { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
               else
                {
                 if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
                  $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
                 else
                  $Value = $i;
                }

               $ID++; $Skipped = TRUE;
               if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) )
                {
                 $Bounds = $this->drawText($XPos,$YPos-$OuterTickWidth-$YLabelOffset,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
                 $TxtBox = $YPos-$OuterTickWidth-2-($Bounds[0]["Y"]-$Bounds[2]["Y"]);
                 $MinTop = min($MinTop,$TxtBox);
                 $LastValue = $Value;
                 $Skipped   = FALSE;
                }

               if ( $Skipped )
                {
                 if ( $DrawXLines ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$SkippedAxisColor); }
                 if ( $SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0 ) { $this->drawLine($XPos,$YPos+$SkippedInnerTickWidth,$XPos,$YPos-$SkippedOuterTickWidth,$SkippedTickColor); }
                }
               else
                {
                 if ( $DrawXLines ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
                 if ( $InnerTickWidth !=0 || $OuterTickWidth != 0 ) { $this->drawLine($XPos,$YPos+$InnerTickWidth,$XPos,$YPos-$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
                }

              }
             if ( isset($Parameters["Name"]) )
              {
               $YPos   = $MinTop-2;
               $XPos   = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
               $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
               $MinTop = $Bounds[2]["Y"];

               $this->DataSet->Data["GraphArea"]["Y1"] = $MinTop;
              }

             $AxisPos["T"] = $MinTop - $ScaleSpacing;
            }
          }
         elseif ( $Pos == SCALE_POS_TOPBOTTOM )
          {
           if ( $Parameters["Position"] == AXIS_POSITION_LEFT )
            {
             if ( $LabelRotation == 0 )					{ $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = -2; }
             if ( $LabelRotation > 0 && $LabelRotation < 190 )		{ $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = -6; }
             if ( $LabelRotation == 180 )				{ $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = -2; }
             if ( $LabelRotation > 180 && $LabelRotation < 360 )	{ $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = -5; }

             if ( $Floating )
              { $FloatingOffset = $YMargin; $this->drawLine($AxisPos["L"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["L"],$this->GraphAreaY2-$Parameters["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
             else
              { $FloatingOffset = 0; $this->drawLine($AxisPos["L"],$this->GraphAreaY1,$AxisPos["L"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }

             if ( $DrawArrows ) { $this->drawArrow($AxisPos["L"],$this->GraphAreaY2-$Parameters["Margin"],$AxisPos["L"],$this->GraphAreaY2+($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }

             $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;

             if ($Parameters["Rows"] == 0 ) { $Step  = $Height; } else { $Step   = $Height / $Parameters["Rows"]; }

             $MinLeft = $AxisPos["L"];
             for($i=0;$i<=$Parameters["Rows"];$i++)
              {
               $YPos  = $this->GraphAreaY1 + $Parameters["Margin"] + $Step*$i;
               $XPos  = $AxisPos["L"];

               if ( $Abscissa != NULL )
                { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
               else
                {
                 if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
                  $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
                 else
                  $Value = $i;
                }

               $ID++; $Skipped = TRUE;
               if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) )
                {
                 $Bounds  = $this->drawText($XPos-$OuterTickWidth+$XLabelOffset,$YPos,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
                 $TxtBox  = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
                 $MinLeft = min($MinLeft,$TxtBox);
                 $LastValue = $Value;
                 $Skipped   = FALSE;
                }

               if ( $Skipped )
                {
                 if ( $DrawXLines ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,$SkippedAxisColor); }
                 if ( $SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0 ) { $this->drawLine($XPos-$SkippedOuterTickWidth,$YPos,$XPos+$SkippedInnerTickWidth,$YPos,$SkippedTickColor); }
                }
               else
                {
                 if ( $DrawXLines && ($YPos != $this->GraphAreaY1 && $YPos != $this->GraphAreaY2) ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
                 if ( $InnerTickWidth !=0 || $OuterTickWidth != 0 ) { $this->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
                }

              }
             if ( isset($Parameters["Name"]) )
              {
               $XPos   = $MinLeft-2;
               $YPos   = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
               $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
               $MinLeft = $Bounds[0]["X"];

               $this->DataSet->Data["GraphArea"]["X1"] = $MinLeft;
              }

             $AxisPos["L"] = $MinLeft - $ScaleSpacing;
            }
           elseif ( $Parameters["Position"] == AXIS_POSITION_RIGHT )
            {
             if ( $LabelRotation == 0 )					{ $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = 2; }
             if ( $LabelRotation > 0 && $LabelRotation < 190 )		{ $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = 6; }
             if ( $LabelRotation == 180 )				{ $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = 5; }
             if ( $LabelRotation > 180 && $LabelRotation < 360 )	{ $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = 7; }

             if ( $Floating )
              { $FloatingOffset = $YMargin; $this->drawLine($AxisPos["R"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["R"],$this->GraphAreaY2-$Parameters["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
             else
              { $FloatingOffset = 0; $this->drawLine($AxisPos["R"],$this->GraphAreaY1,$AxisPos["R"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }

             if ( $DrawArrows ) { $this->drawArrow($AxisPos["R"],$this->GraphAreaY2-$Parameters["Margin"],$AxisPos["R"],$this->GraphAreaY2+($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }

             $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;

             if ($Parameters["Rows"] == 0 ) { $Step  = $Height; } else { $Step   = $Height / $Parameters["Rows"]; }
             
             $MaxRight = $AxisPos["R"];
             for($i=0;$i<=$Parameters["Rows"];$i++)
              {
               $YPos  = $this->GraphAreaY1 + $Parameters["Margin"] + $Step*$i;
               $XPos  = $AxisPos["R"];

               if ( $Abscissa != NULL )
                { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
               else
                {
                 if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
                  $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
                 else
                  $Value = $i;
                }

               $ID++; $Skipped = TRUE;
               if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) )
                {
                 $Bounds   = $this->drawText($XPos+$OuterTickWidth+$XLabelOffset,$YPos,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
                 $TxtBox   = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
                 $MaxRight = max($MaxRight,$TxtBox);
                 $LastValue = $Value;
                 $Skipped   = FALSE;
                }

               if ( $Skipped )
                {
                 if ( $DrawXLines ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,$SkippedAxisColor); }
                 if ( $SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0 ) { $this->drawLine($XPos+$SkippedOuterTickWidth,$YPos,$XPos-$SkippedInnerTickWidth,$YPos,$SkippedTickColor); }
                }
               else
                {
                 if ( $DrawXLines ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
                 if ( $InnerTickWidth !=0 || $OuterTickWidth != 0 ) { $this->drawLine($XPos+$OuterTickWidth,$YPos,$XPos-$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
                }

              }
             if ( isset($Parameters["Name"]) )
              {
               $XPos   = $MaxRight+4;
               $YPos   = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
               $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
               $MaxRight = $Bounds[1]["X"];

               $this->DataSet->Data["GraphArea"]["X2"] = $MaxRight + $this->FontSize;
              }

             $AxisPos["R"] = $MaxRight + $ScaleSpacing;
            }
          }
        }



       if ( $Parameters["Identity"] == AXIS_Y )
        {
         if ( $Pos == SCALE_POS_LEFTRIGHT )
          {
           if ( $Parameters["Position"] == AXIS_POSITION_LEFT )
            {

             if ( $Floating )
              { $FloatingOffset = $XMargin; $this->drawLine($AxisPos["L"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["L"],$this->GraphAreaY2-$Parameters["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
             else
              { $FloatingOffset = 0; $this->drawLine($AxisPos["L"],$this->GraphAreaY1,$AxisPos["L"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }

             if ( $DrawArrows ) { $this->drawArrow($AxisPos["L"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["L"],$this->GraphAreaY1-($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }

             $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
             $Step   = $Height / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MinLeft = $AxisPos["L"];
             $LastY  = NULL;
             for($i=0;$i<=$Parameters["Rows"];$i++)
              {
               $YPos  = $this->GraphAreaY2 - $Parameters["Margin"] - $Step*$i;
               $XPos  = $AxisPos["L"];
               $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);

               if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
               if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($this->GraphAreaX1+$FloatingOffset,$LastY,$this->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }

               if ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }

               if ( $DrawSubTicks && $i != $Parameters["Rows"] )
                $this->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));

               $this->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
               $Bounds  = $this->drawText($XPos-$OuterTickWidth-2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLERIGHT));
               $TxtLeft = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
               $MinLeft = min($MinLeft,$TxtLeft);

               $LastY = $YPos;
              }

             if ( isset($Parameters["Name"]) )
              {
               $XPos    = $MinLeft-2;
               $YPos    = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
               $Bounds  = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
               $MinLeft = $Bounds[2]["X"];

               $this->DataSet->Data["GraphArea"]["X1"] = $MinLeft;
              }

             $AxisPos["L"] = $MinLeft - $ScaleSpacing;
            }
           elseif ( $Parameters["Position"] == AXIS_POSITION_RIGHT )
            {
             if ( $Floating )
              { $FloatingOffset = $XMargin; $this->drawLine($AxisPos["R"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["R"],$this->GraphAreaY2-$Parameters["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
             else
              { $FloatingOffset = 0; $this->drawLine($AxisPos["R"],$this->GraphAreaY1,$AxisPos["R"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }

             if ( $DrawArrows ) { $this->drawArrow($AxisPos["R"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["R"],$this->GraphAreaY1-($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }

             $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
             $Step   = $Height / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MaxLeft = $AxisPos["R"];
             $LastY  = NULL;
             for($i=0;$i<=$Parameters["Rows"];$i++)
              {
               $YPos  = $this->GraphAreaY2 - $Parameters["Margin"] - $Step*$i;
               $XPos  = $AxisPos["R"];
               $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);

               if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
               if ( $LastY != NULL && $CycleBackground  && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($this->GraphAreaX1+$FloatingOffset,$LastY,$this->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }

               if ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }

               if ( $DrawSubTicks && $i != $Parameters["Rows"] )
                $this->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));

               $this->drawLine($XPos-$InnerTickWidth,$YPos,$XPos+$OuterTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
               $Bounds  = $this->drawText($XPos+$OuterTickWidth+2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLELEFT));
               $TxtLeft = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
               $MaxLeft = max($MaxLeft,$TxtLeft);

               $LastY = $YPos;
              }

             if ( isset($Parameters["Name"]) )
              {
               $XPos    = $MaxLeft+6;
               $YPos    = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
               $Bounds  = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
               $MaxLeft = $Bounds[2]["X"];

               $this->DataSet->Data["GraphArea"]["X2"] = $MaxLeft + $this->FontSize;
              }
             $AxisPos["R"] = $MaxLeft + $ScaleSpacing;
            }
          }
         elseif ( $Pos == SCALE_POS_TOPBOTTOM )
          {
           if ( $Parameters["Position"] == AXIS_POSITION_TOP )
            {
             if ( $Floating )
              { $FloatingOffset = $XMargin; $this->drawLine($this->GraphAreaX1+$Parameters["Margin"],$AxisPos["T"],$this->GraphAreaX2-$Parameters["Margin"],$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
             else
              { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["T"],$this->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }

             if ( $DrawArrows ) { $this->drawArrow($this->GraphAreaX2-$Parameters["Margin"],$AxisPos["T"],$this->GraphAreaX2+($ArrowSize*2),$AxisPos["T"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }

             $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
             $Step   = $Width / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MinTop = $AxisPos["T"];
             $LastX  = NULL;
             for($i=0;$i<=$Parameters["Rows"];$i++)
              {
               $XPos  = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
               $YPos  = $AxisPos["T"];
               $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);

               if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
               if ( $LastX != NULL && $CycleBackground  && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($LastX,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$BGColor); }

               if ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }

               if ( $DrawSubTicks && $i != $Parameters["Rows"] )
                $this->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));

               $this->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
               $Bounds    = $this->drawText($XPos,$YPos-$OuterTickWidth-2,$Value,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
               $TxtHeight = $YPos-$OuterTickWidth-2-($Bounds[1]["Y"]-$Bounds[2]["Y"]);
               $MinTop    = min($MinTop,$TxtHeight);

               $LastX = $XPos;
              }

             if ( isset($Parameters["Name"]) )
              {
               $YPos   = $MinTop-2;
               $XPos   = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
               $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
               $MinTop = $Bounds[2]["Y"];

               $this->DataSet->Data["GraphArea"]["Y1"] = $MinTop;
              }

             $AxisPos["T"] = $MinTop - $ScaleSpacing;
            }
           elseif ( $Parameters["Position"] == AXIS_POSITION_BOTTOM )
            {
             if ( $Floating )
              { $FloatingOffset = $XMargin; $this->drawLine($this->GraphAreaX1+$Parameters["Margin"],$AxisPos["B"],$this->GraphAreaX2-$Parameters["Margin"],$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
             else
              { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["B"],$this->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }

             if ( $DrawArrows ) { $this->drawArrow($this->GraphAreaX2-$Parameters["Margin"],$AxisPos["B"],$this->GraphAreaX2+($ArrowSize*2),$AxisPos["B"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }

             $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
             $Step   = $Width / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MaxBottom = $AxisPos["B"];
             $LastX  = NULL;
             for($i=0;$i<=$Parameters["Rows"];$i++)
              {
               $XPos  = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
               $YPos  = $AxisPos["B"];
               $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);

               if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
               if ( $LastX != NULL && $CycleBackground  && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($LastX,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$BGColor); }

               if ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }

               if ( $DrawSubTicks && $i != $Parameters["Rows"] )
                $this->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));

               $this->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
               $Bounds    = $this->drawText($XPos,$YPos+$OuterTickWidth+2,$Value,array("Align"=>TEXT_ALIGN_TOPMIDDLE));
               $TxtHeight = $YPos+$OuterTickWidth+2+($Bounds[1]["Y"]-$Bounds[2]["Y"]);
               $MaxBottom = max($MaxBottom,$TxtHeight);

               $LastX = $XPos;
              }

             if ( isset($Parameters["Name"]) )
              {
               $YPos   = $MaxBottom+2;
               $XPos   = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
               $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
               $MaxBottom = $Bounds[0]["Y"];

               $this->DataSet->Data["GraphArea"]["Y2"] = $MaxBottom + $this->FontSize;
              }

             $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
            }
          }
        }
      }
    }

   function isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip)
    {
     if ( $LabelingMethod == LABELING_DIFFERENT && $Value != $LastValue ) { return(TRUE); }
     if ( $LabelingMethod == LABELING_DIFFERENT && $Value == $LastValue ) { return(FALSE); }
     if ( $LabelingMethod == LABELING_ALL && $LabelSkip == 0 ) { return(TRUE); }
     if ( $LabelingMethod == LABELING_ALL && ($ID+$LabelSkip) % ($LabelSkip+1) != 1 ) { return(FALSE); }

     return(TRUE);
    }

   /* Compute the scale, check for the best visual factors */
   function computeScale($XMin,$XMax,$MaxDivs,$Factors,$AxisID=0)
    {
     /* Compute each factors */
     $Results = "";
     foreach ($Factors as $Key => $Factor)
      $Results[$Factor] = $this->processScale($XMin,$XMax,$MaxDivs,array($Factor),$AxisID);

     /* Remove scales that are creating to much decimals */
     $GoodScaleFactors = "";
     foreach ($Results as $Key => $Result)
      {
       $Decimals = preg_split("/\./",$Result["RowHeight"]);
       if ( (!isset($Decimals[1])) || (strlen($Decimals[1]) < 6) ) { $GoodScaleFactors[] = $Key; }
      }

     /* Found no correct scale, shame,... returns the 1st one as default */
     if ( $GoodScaleFactors == "" ) { return($Results[$Factors[0]]); }

     /* Find the factor that cause the maximum number of Rows */
     $MaxRows = 0; $BestFactor = 0;
     foreach($GoodScaleFactors as $Key => $Factor)
      { if ( $Results[$Factor]["Rows"] > $MaxRows ) { $MaxRows = $Results[$Factor]["Rows"]; $BestFactor = $Factor; } }

     /* Return the best visual scale */
     return($Results[$BestFactor]);
    }

   /* Compute the best matching scale based on size & factors */
   function processScale($XMin,$XMax,$MaxDivs,$Factors,$AxisID)
    {
     $ScaleHeight = abs(ceil($XMax)-floor($XMin));

     if ( isset($this->DataSet->Data["Axis"][$AxisID]["Format"]) )
      $Format = $this->DataSet->Data["Axis"][$AxisID]["Format"];
     else
      $Format = NULL;

     if ( isset($this->DataSet->Data["Axis"][$AxisID]["Display"]) )
      $Mode = $this->DataSet->Data["Axis"][$AxisID]["Display"];
     else
      $Mode = AXIS_FORMAT_DEFAULT;

     $Scale = "";
     if ( $XMin != $XMax )
      {
       $Found = FALSE; $Rescaled = FALSE; $Scaled10Factor = .0001; $Result = 0;
       while(!$Found)
        {
         foreach($Factors as $Key => $Factor)
          {
           if ( !$Found )
            {
             if ( !($this->modulo($XMin,$Factor*$Scaled10Factor) == 0) || ($XMin != floor($XMin))) { $XMinRescaled = floor($XMin/($Factor*$Scaled10Factor))*$Factor*$Scaled10Factor; } else { $XMinRescaled = $XMin; }
             if ( !($this->modulo($XMax,$Factor*$Scaled10Factor) == 0) || ($XMax != floor($XMax))) { $XMaxRescaled = floor($XMax/($Factor*$Scaled10Factor))*$Factor*$Scaled10Factor+($Factor*$Scaled10Factor); } else { $XMaxRescaled = $XMax; }
             $ScaleHeightRescaled = abs($XMaxRescaled-$XMinRescaled);

             if ( !$Found && floor($ScaleHeightRescaled/($Factor*$Scaled10Factor)) <= $MaxDivs ) { $Found = TRUE; $Rescaled = TRUE; $Result = $Factor * $Scaled10Factor; }
            }
          }
         $Scaled10Factor = $Scaled10Factor * 10;
        }

       /* ReCall Min / Max / Height */
       if ( $Rescaled ) { $XMin = $XMinRescaled; $XMax = $XMaxRescaled; $ScaleHeight = $ScaleHeightRescaled; }

       /* Compute rows size */
       $Rows      = floor($ScaleHeight / $Result); if ( $Rows == 0 ) { $Rows = 1; }
       $RowHeight = $ScaleHeight / $Rows;

       /* Return the results */
       $Scale["Rows"] = $Rows; $Scale["RowHeight"] = $RowHeight; $Scale["XMin"] = $XMin;  $Scale["XMax"] = $XMax;

       /* Compute the needed decimals for the metric view to avoid repetition of the same X Axis labels */
       if ( $Mode == AXIS_FORMAT_METRIC && $Format == NULL )
        {
         $Done = FALSE; $GoodDecimals = 0;
         for($Decimals=0;$Decimals<=10;$Decimals++)
          {
           if ( !$Done )
            {
             $LastLabel = "zob"; $ScaleOK = TRUE;
             for($i=0;$i<=$Rows;$i++)
              {
               $Value = $XMin + $i*$RowHeight;
               $Label = $this->scaleFormat($Value,AXIS_FORMAT_METRIC,$Decimals);

               if ( $LastLabel == $Label ) { $ScaleOK = FALSE; }
               $LastLabel = $Label;
              }
             if ( $ScaleOK ) { $Done = TRUE; $GoodDecimals = $Decimals; }
            }
          }

         $Scale["Format"] = $GoodDecimals;
        }
      }
     else
      {
       /* If all values are the same we keep a +1/-1 scale */
       $Rows = 2; $XMin = $XMax-1; $XMax = $XMax+1; $RowHeight = 1;

       /* Return the results */
       $Scale["Rows"] = $Rows; $Scale["RowHeight"] = $RowHeight; $Scale["XMin"] = $XMin;  $Scale["XMax"] = $XMax;
      }

     return($Scale);
    }

   function modulo($Value1,$Value2)
    {
     if (floor($Value2) == 0) { return(0); }
     if (floor($Value2) != 0) { return($Value1 % $Value2); }

     $MinValue = min($Value1,$Value2); $Factor = 10;
     while ( floor($MinValue*$Factor) == 0 )
      { $Factor = $Factor * 10; }

     return(($Value1*$Factor) % ($Value2*$Factor));
    }

   /* Draw a threshold with the computed scale */
   function drawThreshold($Value,$Format="")
    {
     $AxisID		= isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
     $R			= isset($Format["R"]) ? $Format["R"] : 255;
     $G			= isset($Format["G"]) ? $Format["G"] : 0;
     $B			= isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : 50;
     $Weight		= isset($Format["Weight"]) ? $Format["Weight"] : NULL;
     $Ticks		= isset($Format["Ticks"]) ? $Format["Ticks"] : 6;
     $Wide		= isset($Format["Wide"]) ? $Format["Wide"] : FALSE;
     $WideFactor	= isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
     $WriteCaption	= isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : FALSE;
     $Caption		= isset($Format["Caption"]) ? $Format["Caption"] : NULL;
     $CaptionAlign	= isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
     $CaptionOffset     = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 10;
     $CaptionR		= isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
     $CaptionG		= isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
     $CaptionB		= isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
     $CaptionAlpha	= isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
     $DrawBox		= isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
     $DrawBoxBorder	= isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
     $BorderOffset	= isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 3;
     $BoxRounded	= isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
     $RoundedRadius	= isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
     $BoxR		= isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
     $BoxG		= isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
     $BoxB		= isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
     $BoxAlpha		= isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 30;
     $BoxSurrounding	= isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
     $BoxBorderR	= isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
     $BoxBorderG	= isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
     $BoxBorderB	= isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
     $BoxBorderAlpha	= isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;

     $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
                              "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
                              "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha,
                              "R"=>$CaptionR,"G"=>$CaptionG,"B"=>$CaptionB,"Alpha"=>$CaptionAlpha);

     if ( $Caption == NULL ) { $Caption = $Value; }

     $Data = $this->DataSet->getData();
     if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }

     if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
      {
       $YPos = $this->scaleComputeY($Value,array("AxisID"=>$AxisID));
       if ( $YPos >= $this->GraphAreaY1 && $YPos <= $this->GraphAreaY2 )
        {
         $this->drawLine($this->GraphAreaX1,$YPos,$this->GraphAreaX2,$YPos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));

         if ( $Wide )
          {
           $this->drawLine($this->GraphAreaX1,$YPos-1,$this->GraphAreaX2,$YPos-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
           $this->drawLine($this->GraphAreaX1,$YPos+1,$this->GraphAreaX2,$YPos+1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
          }

         if ( $WriteCaption )
          {
           if ( $CaptionAlign == CAPTION_LEFT_TOP )
            { $X = $this->GraphAreaX1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT; }
           else 
            { $X = $this->GraphAreaX2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT; }
           
           $this->drawText($X,$YPos,$Caption,$CaptionSettings);
          }
        }

       return(array("Y"=>$YPos));
      }

     if ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
      {
       $XPos = $this->scaleComputeY($Value,array("AxisID"=>$AxisID));
       if ( $XPos >= $this->GraphAreaX1 && $XPos <= $this->GraphAreaX2 )
        {
         $this->drawLine($XPos,$this->GraphAreaY1,$XPos,$this->GraphAreaY2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));

         if ( $Wide )
          {
           $this->drawLine($XPos-1,$this->GraphAreaY1,$XPos-1,$this->GraphAreaY2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
           $this->drawLine($XPos+1,$this->GraphAreaY1,$XPos+1,$this->GraphAreaY2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
          }

         if ( $WriteCaption )
          {
           if ( $CaptionAlign == CAPTION_LEFT_TOP )
            { $Y = $this->GraphAreaY1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE; }
           else 
            { $Y = $this->GraphAreaY2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; }

           $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
           $this->drawText($XPos,$Y,$Caption,$CaptionSettings);
          }
        }

       return(array("Y"=>$XPos));
      }
    }

   /* Draw a threshold with the computed scale */
   function drawThresholdArea($Value1,$Value2,$Format="")
    {
     $AxisID	= isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
     $R		= isset($Format["R"]) ? $Format["R"] : 255;
     $G		= isset($Format["G"]) ? $Format["G"] : 0;
     $B		= isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha	= isset($Format["Alpha"]) ? $Format["Alpha"] : 20;
     $Border    = isset($Format["Border"]) ? $Format["Border"] : TRUE;
     $BorderR   = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
     $BorderG   = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
     $BorderB   = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
     $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20;
     $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2;

     if ($BorderAlpha >100) { $BorderAlpha = 100;}

     $Data = $this->DataSet->getData();
     if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }

     if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
      {
       $YPos1 = $this->scaleComputeY($Value1,array("AxisID"=>$AxisID));
       $YPos2 = $this->scaleComputeY($Value2,array("AxisID"=>$AxisID));

       if ( $YPos1 > $this->GraphAreaY2 ) { $YPos1 = $this->GraphAreaY2; } if ( $YPos1 < $this->GraphAreaY1 ) { $YPos1 = $this->GraphAreaY1; }
       if ( $YPos2 > $this->GraphAreaY2 ) { $YPos2 = $this->GraphAreaY2; } if ( $YPos2 < $this->GraphAreaY1 ) { $YPos2 = $this->GraphAreaY1; }

       $this->drawFilledRectangle($this->GraphAreaX1+1,$YPos1,$this->GraphAreaX2-1,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
       if ( $Border )
        {
         $this->drawLine($this->GraphAreaX1+1,$YPos1,$this->GraphAreaX2-1,$YPos1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
         $this->drawLine($this->GraphAreaX1+1,$YPos2,$this->GraphAreaX2-1,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
        }
       return(array("Y1"=>$YPos1,"Y2"=>$YPos2));
      }

     if ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
      {
       $XPos1 = $this->scaleComputeY($Value1,array("AxisID"=>$AxisID));
       $XPos2 = $this->scaleComputeY($Value2,array("AxisID"=>$AxisID));

       if ( $XPos1 > $this->GraphAreaX2 ) { $XPos1 = $this->GraphAreaX2; } if ( $XPos1 < $this->GraphAreaX1 ) { $XPos1 = $this->GraphAreaX1; }
       if ( $XPos2 > $this->GraphAreaX2 ) { $XPos2 = $this->GraphAreaX2; } if ( $XPos2 < $this->GraphAreaX1 ) { $XPos2 = $this->GraphAreaX1; }

       $this->drawFilledRectangle($XPos1,$this->GraphAreaY1+1,$XPos2,$this->GraphAreaY2-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
       if ( $Border )
        {
         $this->drawLine($XPos1,$this->GraphAreaY1+1,$XPos1,$this->GraphAreaY2-1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
         $this->drawLine($XPos2,$this->GraphAreaY1+1,$XPos2,$this->GraphAreaY2-1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
        }
       return(array("Y1"=>$XPos1,"Y2"=>$XPos2));
      }
    }

   function scaleGetXSettings()
    {
     $Data = $this->DataSet->getData();
     foreach($Data["Axis"] as $AxisID => $Settings)
      {
       if ( $Settings["Identity"] == AXIS_X )
        {
         $Rows = $Settings["Rows"];

         return(array($Settings["Margin"],$Rows));
        }
      }
    }

   function scaleComputeY($Values,$Option="",$ReturnOnly0Height=FALSE)
    {
     $AxisID	= isset($Option["AxisID"]) ? $Option["AxisID"] : 0;
     $SerieName	= isset($Option["SerieName"]) ? $Option["SerieName"] : NULL;

     $Data = $this->DataSet->getData();
     if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }

     if ( $SerieName != NULL ) { $AxisID = $Data["Series"][$SerieName]["Axis"]; }
     if ( !is_array($Values) ) { $tmp = $Values; $Values = ""; $Values[0] = $tmp; }

     $Result = "";
     if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
      {
       $Height      = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Data["Axis"][$AxisID]["Margin"]*2;
       $ScaleHeight = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
       $Step        = $Height / $ScaleHeight;

       if ( $ReturnOnly0Height )
        { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $Step * $Value; } } }
       else
        { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $this->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"])); } } }
      }
     else
      {
       $Width      = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Data["Axis"][$AxisID]["Margin"]*2;
       $ScaleWidth = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
       $Step       = $Width / $ScaleWidth;

       if ( $ReturnOnly0Height )
        { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $Step * $Value; } } }
       else
        { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $this->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"])); } } }
      }

     if ( count($Result) == 1 )
      return($Result[0]);
     else
      return($Result);
    }

   /* Format the axis values */
   function scaleFormat($Value,$Mode=NULL,$Format=NULL,$Unit=NULL)
    {
     if ( $Value == VOID ) { return(""); }

     if ( $Mode == AXIS_FORMAT_DATE )
      { if ( $Format == NULL ) { $Pattern = "d/m/Y"; } else { $Pattern = $Format; } return(date($Pattern,$Value)); }

     if ( $Mode == AXIS_FORMAT_TIME )
      { if ( $Format == NULL ) { $Pattern = "H:i:s"; } else { $Pattern = $Format; } return(date($Pattern,$Value)); }

     if ( $Mode == AXIS_FORMAT_CURRENCY )
      { return($Format.number_format($Value,2)); }

     if ( $Mode == AXIS_FORMAT_METRIC )
      {
       if (abs($Value) > 1000000000)
        return(round($Value/1000000000,$Format)."g".$Unit);
       if (abs($Value) > 1000000)
        return(round($Value/1000000,$Format)."m".$Unit);
       elseif (abs($Value) >= 1000)
        return(round($Value/1000,$Format)."k".$Unit);
       
      }
     return($Value.$Unit);
    }

   /* Write Max value on a chart */
   function writeBounds($Type=BOUND_BOTH,$Format=NULL)
    {
     $MaxLabelTxt	= isset($Format["MaxLabelTxt"]) ? $Format["MaxLabelTxt"] : "max=";
     $MinLabelTxt	= isset($Format["MinLabelTxt"]) ? $Format["MinLabelTxt"] : "min=";
     $Decimals		= isset($Format["Decimals"]) ? $Format["Decimals"] : 1;
     $ExcludedSeries	= isset($Format["ExcludedSeries"]) ? $Format["ExcludedSeries"] : "";
     $DisplayOffset	= isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 4;
     $DisplayColor	= isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
     $MaxDisplayR	= isset($Format["MaxDisplayR"]) ? $Format["MaxDisplayR"] : 0;
     $MaxDisplayG	= isset($Format["MaxDisplayG"]) ? $Format["MaxDisplayG"] : 0;
     $MaxDisplayB	= isset($Format["MaxDisplayB"]) ? $Format["MaxDisplayB"] : 0;
     $MinDisplayR	= isset($Format["MinDisplayR"]) ? $Format["MinDisplayR"] : 255;
     $MinDisplayG	= isset($Format["MinDisplayG"]) ? $Format["MinDisplayG"] : 255;
     $MinDisplayB	= isset($Format["MinDisplayB"]) ? $Format["MinDisplayB"] : 255;
     $MinLabelPos	= isset($Format["MinLabelPos"]) ? $Format["MinLabelPos"] : BOUND_LABEL_POS_AUTO;
     $MaxLabelPos	= isset($Format["MaxLabelPos"]) ? $Format["MaxLabelPos"] : BOUND_LABEL_POS_AUTO;
     $DrawBox		= isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
     $DrawBoxBorder	= isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
     $BorderOffset	= isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 3;
     $BoxRounded	= isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
     $RoundedRadius	= isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
     $BoxR		= isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
     $BoxG		= isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
     $BoxB		= isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
     $BoxAlpha		= isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
     $BoxSurrounding	= isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
     $BoxBorderR	= isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
     $BoxBorderG	= isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
     $BoxBorderB	= isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
     $BoxBorderAlpha	= isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;

     $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
                              "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
                              "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha);

     list($XMargin,$XDivs) = $this->scaleGetXSettings();

     $Data = $this->DataSet->getData();
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && !isset($ExcludedSeries[$SerieName]))
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
         if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }

         $MinValue = $this->DataSet->getMin($SerieName);
         $MaxValue = $this->DataSet->getMax($SerieName);

         $MinPos = VOID; $MaxPos = VOID;
         foreach($Serie["Data"] as $Key => $Value)
          { 
           if ( $Value == $MinValue && $MinPos == VOID ) { $MinPos = $Key; }
           if ( $Value == $MaxValue ) { $MaxPos = $Key; }
          }

         $AxisID	= $Serie["Axis"];
         $Mode		= $Data["Axis"][$AxisID]["Display"];
         $Format	= $Data["Axis"][$AxisID]["Format"];
         $Unit		= $Data["Axis"][$AxisID]["Unit"];

         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           $XStep       = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs;
           $X           = $this->GraphAreaX1 + $XMargin;
           $SerieOffset = isset($Serie["XOffset"]) ? $Serie["XOffset"] : 0;

           if ( $Type == BOUND_MAX || $Type == BOUND_BOTH )
            {
             if ( $MaxLabelPos == BOUND_LABEL_POS_TOP    || ( $MaxLabelPos ==  BOUND_LABEL_POS_AUTO && $MaxValue >= 0) ) { $YPos  = $PosArray[$MaxPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_BOTTOMMIDDLE; }
             if ( $MaxLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MaxLabelPos ==  BOUND_LABEL_POS_AUTO && $MaxValue < 0) ) { $YPos  = $PosArray[$MaxPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_TOPMIDDLE; }

             $XPos  = $X + $MaxPos*$XStep + $SerieOffset;
             $Label = $MaxLabelTxt.$this->scaleFormat(round($MaxValue,$Decimals),$Mode,$Format,$Unit);

             $TxtPos  = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$Label);
             $XOffset = 0; $YOffset = 0;
             if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = (($this->GraphAreaX1 - $TxtPos[0]["X"])/2); }
             if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -(($TxtPos[1]["X"] - $this->GraphAreaX2)/2); }
             if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $TxtPos[2]["Y"]; }
             if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -($TxtPos[0]["Y"] - $this->GraphAreaY2); }

             $CaptionSettings["R"] = $MaxDisplayR; $CaptionSettings["G"] = $MaxDisplayG;
             $CaptionSettings["B"] = $MaxDisplayB; $CaptionSettings["Align"] = $Align;

             $this->drawText($XPos+$XOffset,$YPos+$YOffset,$Label,$CaptionSettings);
            }

           if ( $Type == BOUND_MIN || $Type == BOUND_BOTH )
            {
             if ( $MinLabelPos == BOUND_LABEL_POS_TOP    || ( $MinLabelPos ==  BOUND_LABEL_POS_AUTO && $MinValue >= 0) ) { $YPos  = $PosArray[$MinPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_BOTTOMMIDDLE; }
             if ( $MinLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MinLabelPos ==  BOUND_LABEL_POS_AUTO && $MinValue < 0) ) { $YPos  = $PosArray[$MinPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_TOPMIDDLE; }

             $XPos  = $X + $MinPos*$XStep + $SerieOffset;
             $Label = $MinLabelTxt.$this->scaleFormat(round($MinValue,$Decimals),$Mode,$Format,$Unit);

             $TxtPos  = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$Label);
             $XOffset = 0; $YOffset = 0;
             if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = (($this->GraphAreaX1 - $TxtPos[0]["X"])/2); }
             if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -(($TxtPos[1]["X"] - $this->GraphAreaX2)/2); }
             if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $TxtPos[2]["Y"]; }
             if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -($TxtPos[0]["Y"] - $this->GraphAreaY2); }

             $CaptionSettings["R"] = $MinDisplayR; $CaptionSettings["G"] = $MinDisplayG;
             $CaptionSettings["B"] = $MinDisplayB; $CaptionSettings["Align"] = $Align;

             $this->drawText($XPos+$XOffset,$YPos-$DisplayOffset+$YOffset,$Label,$CaptionSettings);
            }
          }
         else
          {
           $XStep       = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs;
           $X           = $this->GraphAreaY1 + $XMargin;
           $SerieOffset = isset($Serie["XOffset"]) ? $Serie["XOffset"] : 0;

           if ( $Type == BOUND_MAX || $Type == BOUND_BOTH )
            {
             if ( $MaxLabelPos == BOUND_LABEL_POS_TOP    || ( $MaxLabelPos ==  BOUND_LABEL_POS_AUTO && $MaxValue >= 0) ) { $YPos  = $PosArray[$MaxPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLELEFT; }
             if ( $MaxLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MaxLabelPos ==  BOUND_LABEL_POS_AUTO && $MaxValue < 0) ) { $YPos  = $PosArray[$MaxPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLERIGHT; }

             $XPos  = $X + $MaxPos*$XStep + $SerieOffset;
             $Label = $MaxLabelTxt.$this->scaleFormat($MaxValue,$Mode,$Format,$Unit);

             $TxtPos  = $this->getTextBox($YPos,$XPos,$this->FontName,$this->FontSize,0,$Label);
             $XOffset = 0; $YOffset = 0;
             if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $TxtPos[0]["X"]; }
             if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -($TxtPos[1]["X"] - $this->GraphAreaX2); }
             if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = ($this->GraphAreaY1 - $TxtPos[2]["Y"])/2; }
             if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -(($TxtPos[0]["Y"] - $this->GraphAreaY2)/2);}

             $CaptionSettings["R"] = $MaxDisplayR; $CaptionSettings["G"] = $MaxDisplayG;
             $CaptionSettings["B"] = $MaxDisplayB; $CaptionSettings["Align"] = $Align;

             $this->drawText($YPos+$XOffset,$XPos+$YOffset,$Label,$CaptionSettings);
            }

           if ( $Type == BOUND_MIN || $Type == BOUND_BOTH )
            {
             if ( $MinLabelPos == BOUND_LABEL_POS_TOP    || ( $MinLabelPos ==  BOUND_LABEL_POS_AUTO && $MinValue >= 0) ) { $YPos  = $PosArray[$MinPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLELEFT; }
             if ( $MinLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MinLabelPos ==  BOUND_LABEL_POS_AUTO && $MinValue < 0) ) { $YPos  = $PosArray[$MinPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLERIGHT; }

             $XPos  = $X + $MinPos*$XStep + $SerieOffset;
             $Label = $MinLabelTxt.$this->scaleFormat($MinValue,$Mode,$Format,$Unit);

             $TxtPos  = $this->getTextBox($YPos,$XPos,$this->FontName,$this->FontSize,0,$Label);
             $XOffset = 0; $YOffset = 0;
             if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $TxtPos[0]["X"]; }
             if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -($TxtPos[1]["X"] - $this->GraphAreaX2); }
             if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = ($this->GraphAreaY1 - $TxtPos[2]["Y"])/2; }
             if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -(($TxtPos[0]["Y"] - $this->GraphAreaY2)/2);}

             $CaptionSettings["R"] = $MinDisplayR; $CaptionSettings["G"] = $MinDisplayG;
             $CaptionSettings["B"] = $MinDisplayB; $CaptionSettings["Align"] = $Align;

             $this->drawText($YPos+$XOffset,$XPos+$YOffset,$Label,$CaptionSettings);
            }
          }
        }
      }
    }

   /* Draw a plot chart */
   function drawPlotChart($Format=NULL)
    {
     $PlotSize		= isset($Format["PlotSize"]) ? $Format["PlotSize"] : 3;
     $PlotBorder	= isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : FALSE;
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : 50;
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : 50;
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : 50;
     $BorderAlpha	= isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 30;
     $BorderSize	= isset($Format["BorderSize"]) ? $Format["BorderSize"] : 2;
     $Surrounding	= isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
     $DisplayValues	= isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
     $DisplayOffset	= isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 4;
     $DisplayColor	= isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
     $DisplayR		= isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
     $DisplayG		= isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
     $DisplayB		= isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
     $RecordImageMap	= isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;

     $Data = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();

     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
         if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
         if ( isset($Serie["Picture"]) )
          { $Picture = $Serie["Picture"]; list($PicWidth,$PicHeight,$PicType) = $this->getPicInfo($Picture); }
         else { $Picture = NULL; $PicOffset = 0; }

         if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }

         $AxisID	= $Serie["Axis"];
         $Shape		= $Serie["Shape"];
         $Mode		= $Data["Axis"][$AxisID]["Display"];
         $Format	= $Data["Axis"][$AxisID]["Format"];
         $Unit		= $Data["Axis"][$AxisID]["Unit"];

         if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }

         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));

         $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
           if ( $Picture != NULL ) { $PicOffset = $PicHeight / 2; $PlotSize = 0; }
           $X = $this->GraphAreaX1 + $XMargin;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           foreach($PosArray as $Key => $Y)
            {
             if ( $DisplayValues ) 
              $this->drawText($X,$Y-$DisplayOffset-$PlotSize-$BorderSize-$PicOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));

             if ( $Y != VOID )
              {
               if ( $RecordImageMap ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$PlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }

               if ( $Picture != NULL )
                { $this->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
               else
                { $this->drawShape($X,$Y,$Shape,$PlotSize,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha); }
              }
             $X = $X + $XStep;
            }
          }
         else
          {
           if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
           if ( $Picture != NULL ) { $PicOffset = $PicWidth / 2; $PlotSize = 0; }
           $Y = $this->GraphAreaY1 + $XMargin;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           foreach($PosArray as $Key => $X)
            {
             if ( $DisplayValues ) 
              $this->drawText($X+$DisplayOffset+$PlotSize+$BorderSize+$PicOffset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));

             if ( $X != VOID )
              {
               if ( $RecordImageMap ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$PlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }

               if ( $Picture != NULL )
                { $this->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
               else
                { $this->drawShape($X,$Y,$Shape,$PlotSize,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha); }
              }
             $Y = $Y + $YStep;
            }
          }
        }
      }
    }

   /* Draw a spline chart */
   function drawSplineChart($Format=NULL)
    {
     $BreakVoid		= isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : TRUE;
     $VoidTicks		= isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
     $BreakR		= isset($Format["BreakR"]) ? $Format["BreakR"] : NULL; // 234
     $BreakG		= isset($Format["BreakG"]) ? $Format["BreakG"] : NULL; // 55
     $BreakB		= isset($Format["BreakB"]) ? $Format["BreakB"] : NULL; // 26
     $DisplayValues	= isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
     $DisplayOffset	= isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
     $DisplayColor	= isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
     $DisplayR		= isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
     $DisplayG		= isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
     $DisplayB		= isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
     $RecordImageMap	= isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
     $ImageMapPlotSize  = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;

     $Data = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];

         if ( $BreakR == NULL )
          $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks);
         else
          $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);

         if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }

         $AxisID	= $Serie["Axis"];
         $Mode		= $Data["Axis"][$AxisID]["Display"];
         $Format	= $Data["Axis"][$AxisID]["Format"];
         $Unit		= $Data["Axis"][$AxisID]["Unit"];

         if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }

         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));

         $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
           $X     = $this->GraphAreaX1 + $XMargin; $WayPoints = "";
           $Force = $XStep / 5;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           $LastGoodY = NULL; $LastGoodX = NULL; $LastX = 1; $LastY = 1;
           foreach($PosArray as $Key => $Y)
            {
             if ( $DisplayValues ) 
              $this->drawText($X,$Y-$DisplayOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
	
             if ( $RecordImageMap && $Y != VOID ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }

             if ( $Y == VOID && $LastY != NULL )
              { $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight)); $WayPoints = ""; }

             if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
              { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); }

             if ( $Y != VOID )
              $WayPoints[] = array($X,$Y);

             if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
             if ( $Y == VOID ) { $Y = NULL; }

             $LastX = $X; $LastY = $Y;
             $X = $X + $XStep;
            }
           $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
          }
         else
          {
           if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
           $Y     = $this->GraphAreaY1 + $XMargin; $WayPoints = "";
           $Force = $YStep / 5;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           $LastGoodY = NULL; $LastGoodX = NULL; $LastX = 1; $LastY = 1;
           foreach($PosArray as $Key => $X)
            {
             if ( $DisplayValues ) 
              $this->drawText($X+$DisplayOffset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));

             if ( $RecordImageMap && $X != VOID ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }

             if ( $X == VOID && $LastX != NULL )
              { $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight)); $WayPoints = ""; }

             if ( $X != VOID && $LastX == NULL && $LastGoodX != NULL && !$BreakVoid )
              { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); }

             if ( $X != VOID )
              $WayPoints[] = array($X,$Y);

             if ( $X != VOID ) { $LastGoodX = $X; $LastGoodY = $Y; }
             if ( $X == VOID ) { $X = NULL; }

             $LastX = $X; $LastY = $Y;
             $Y = $Y + $YStep;
            }
           $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
          }
        }
      }
    }

   /* Draw a filled spline chart */
   function drawFilledSplineChart($Format=NULL)
    {
     $DisplayValues	= isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
     $DisplayOffset	= isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
     $DisplayColor	= isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
     $DisplayR		= isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
     $DisplayG		= isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
     $DisplayB		= isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
     $AroundZero	= isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
     $Threshold		= isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;

     $Data = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
         if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }

         $AxisID	= $Serie["Axis"];
         $Mode		= $Data["Axis"][$AxisID]["Display"];
         $Format	= $Data["Axis"][$AxisID]["Format"];
         $Unit		= $Data["Axis"][$AxisID]["Unit"];

         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
         if ( $AroundZero ) { $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"])); }

         if ( $Threshold != NULL )
          {
           foreach($Threshold as $Key => $Params)
            {
             $Threshold[$Key]["MinX"] = $this->scaleComputeY($Params["Min"],array("AxisID"=>$Serie["Axis"]));
             $Threshold[$Key]["MaxX"] = $this->scaleComputeY($Params["Max"],array("AxisID"=>$Serie["Axis"]));
            }
          }

         $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
           $X     = $this->GraphAreaX1 + $XMargin; $WayPoints = "";
           $Force = $XStep / 5;

           if ( !$AroundZero ) { $YZero = $this->GraphAreaY2-1; }
           if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
           if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }

           $LastX = ""; $LastY = "";
           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           foreach($PosArray as $Key => $Y)
            {
             if ( $DisplayValues ) 
              $this->drawText($X,$Y-$DisplayOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));

             if ( $Y == VOID )
              {
               $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));

               if ( $Area != "" )
                {
                 foreach ($Area as $key => $Points)
                  {
                   $Corners = ""; $Corners[] = $Area[$key][0]["X"]; $Corners[] = $YZero;
                   foreach($Points as $subKey => $Point)
                    {
                     if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
                     $Corners[] = $Point["Y"]+1;
                    }
                   $Corners[] = $Points[$subKey]["X"]-1; $Corners[] = $YZero;

                   $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
                  }
                 $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
                }

               $WayPoints = "";
              }
             else
              $WayPoints[] = array($X,$Y-.5); /* -.5 for AA visual fix */

             $X = $X + $XStep;
            }
           $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));

           if ( $Area != "" )
            {
             foreach ($Area as $key => $Points)
              {
               $Corners = ""; $Corners[] = $Area[$key][0]["X"]; $Corners[] = $YZero;
               foreach($Points as $subKey => $Point)
                {
                 if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
                 $Corners[] = $Point["Y"]+1;
                }
               $Corners[] = $Points[$subKey]["X"]-1; $Corners[] = $YZero;

               $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
              }
             $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
            }
          }
         else
          {
           if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
           $Y     = $this->GraphAreaY1 + $XMargin; $WayPoints = "";
           $Force = $YStep / 5;

           if ( !$AroundZero ) { $YZero = $this->GraphAreaX1+1; }
           if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
           if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           foreach($PosArray as $Key => $X)
            {
             if ( $DisplayValues ) 
              $this->drawText($X+$DisplayOffset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));

             if ( $X == VOID )
              {
               $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));

               if ( $Area != "" )
                {
                 foreach ($Area as $key => $Points)
                  {
                   $Corners = ""; $Corners[] = $YZero; $Corners[] = $Area[$key][0]["Y"];
                   foreach($Points as $subKey => $Point)
                    {
                     if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
                     $Corners[] = $Point["Y"];
                    }
                   $Corners[] = $YZero; $Corners[] = $Points[$subKey]["Y"]-1;

                   $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
                  }
                 $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
                }

               $WayPoints = "";
              }
             else
              $WayPoints[] = array($X,$Y);

             $Y = $Y + $YStep;
            }
           $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));

           if ( $Area != "" )
            {
             foreach ($Area as $key => $Points)
              {
               $Corners = ""; $Corners[] = $YZero; $Corners[] = $Area[$key][0]["Y"];
               foreach($Points as $subKey => $Point)
                {
                 if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
                 $Corners[] = $Point["Y"];
                }
               $Corners[] = $YZero; $Corners[] = $Points[$subKey]["Y"]-1;

               $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
              }
             $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
            }

          }
        }
      }
    }

   /* Draw a line chart */
   function drawLineChart($Format=NULL)
    {
     $BreakVoid		= isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : TRUE;
     $VoidTicks		= isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
     $BreakR		= isset($Format["BreakR"]) ? $Format["BreakR"] : NULL;
     $BreakG		= isset($Format["BreakG"]) ? $Format["BreakG"] : NULL;
     $BreakB		= isset($Format["BreakB"]) ? $Format["BreakB"] : NULL;
     $DisplayValues	= isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
     $DisplayOffset	= isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
     $DisplayColor	= isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
     $DisplayR		= isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
     $DisplayG		= isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
     $DisplayB		= isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
     $RecordImageMap	= isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
     $ImageMapPlotSize  = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;

     $Data = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];

         if ( $BreakR == NULL )
          $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
         else
          $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);

         if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }

         $AxisID	= $Serie["Axis"];
         $Mode		= $Data["Axis"][$AxisID]["Display"];
         $Format	= $Data["Axis"][$AxisID]["Format"];
         $Unit		= $Data["Axis"][$AxisID]["Unit"];

         if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }

         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));

         $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
           $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           $LastGoodY = NULL; $LastGoodX = NULL;
           foreach($PosArray as $Key => $Y)
            {
             if ( $DisplayValues && $Serie["Data"][$Key] != VOID ) 
              {
               if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
               $this->drawText($X,$Y-$Offset-$Weight,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
              }

             if ( $RecordImageMap && $Y != VOID ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }

             if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
              $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));

             if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
              { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); $LastGoodY = NULL; }

             if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
             if ( $Y == VOID ) { $Y = NULL; }

             $LastX = $X; $LastY = $Y;
             $X = $X + $XStep;
            }
          }
         else
          {
           if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
           $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           $LastGoodY = NULL; $LastGoodX = NULL;
           foreach($PosArray as $Key => $X)
            {
             if ( $DisplayValues && $Serie["Data"][$Key] != VOID ) 
              { $this->drawText($X+$DisplayOffset+$Weight,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); }

             if ( $RecordImageMap && $X != VOID ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }

             if ( $X != VOID && $LastX != NULL && $LastY != NULL )
              $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));

             if ( $X != VOID && $LastX == NULL && $LastGoodY != NULL && !$BreakVoid )
              { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); $LastGoodY = NULL; }

             if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
             if ( $X == VOID ) { $X = NULL; }

             $LastX = $X; $LastY = $Y;
             $Y = $Y + $YStep;
            }
          }
        }
      }
    }

   /* Draw a line chart */
   function drawZoneChart($SerieA,$SerieB,$Format=NULL)
    {
     $AxisID	= isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
     $LineR	= isset($Format["LineR"]) ? $Format["LineR"] : 150;
     $LineG	= isset($Format["LineG"]) ? $Format["LineG"] : 150;
     $LineB	= isset($Format["LineB"]) ? $Format["LineB"] : 150;
     $LineAlpha	= isset($Format["LineAlpha"]) ? $Format["LineAlpha"] : 50;
     $LineTicks	= isset($Format["LineTicks"]) ? $Format["LineTicks"] : 1;
     $AreaR	= isset($Format["AreaR"]) ? $Format["AreaR"] : 150;
     $AreaG	= isset($Format["AreaG"]) ? $Format["AreaG"] : 150;
     $AreaB	= isset($Format["AreaB"]) ? $Format["AreaB"] : 150;
     $AreaAlpha	= isset($Format["AreaAlpha"]) ? $Format["AreaAlpha"] : 5;

     $Data	 = $this->DataSet->getData();
     if ( !isset($Data["Series"][$SerieA]["Data"]) || !isset($Data["Series"][$SerieB]["Data"]) ) { return(0); }
     $SerieAData = $Data["Series"][$SerieA]["Data"];
     $SerieBData = $Data["Series"][$SerieB]["Data"];

     list($XMargin,$XDivs) = $this->scaleGetXSettings();

     $Mode	= $Data["Axis"][$AxisID]["Display"];
     $Format	= $Data["Axis"][$AxisID]["Format"];
     $Unit	= $Data["Axis"][$AxisID]["Unit"];

     $PosArrayA = $this->scaleComputeY($SerieAData,array("AxisID"=>$AxisID));
     $PosArrayB = $this->scaleComputeY($SerieBData,array("AxisID"=>$AxisID));
     if ( count($PosArrayA) != count($PosArrayB) ) { return(0); }

     if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
      {
       if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
       $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;

       $LastX = NULL; $LastY1 = NULL; $LastY2 = NULL;
       $BoundsA = ""; $BoundsB = "";
       foreach($PosArrayA as $Key => $Y1)
        {
         $Y2 = $PosArrayB[$Key];

         $BoundsA[] = $X; $BoundsA[] = $Y1;
         $BoundsB[] = $X; $BoundsB[] = $Y2;

         $LastX = $X;
         $LastY1 = $Y1; $LastY2 = $Y2;

         $X = $X + $XStep;
        }
       $Bounds = array_merge($BoundsA,$this->reversePlots($BoundsB));
       $this->drawPolygonChart($Bounds,array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"Alpha"=>$AreaAlpha));

       for($i=0;$i<=count($BoundsA)-4;$i=$i+2)
        {
         $this->drawLine($BoundsA[$i],$BoundsA[$i+1],$BoundsA[$i+2],$BoundsA[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
         $this->drawLine($BoundsB[$i],$BoundsB[$i+1],$BoundsB[$i+2],$BoundsB[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
        }
      }
     else
      {
       if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
       $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;

       $LastY = NULL; $LastX1 = NULL; $LastX2 = NULL;
       $BoundsA = ""; $BoundsB = "";
       foreach($PosArrayA as $Key => $X1)
        {
         $X2 = $PosArrayB[$Key];

         $BoundsA[] = $X1; $BoundsA[] = $Y;
         $BoundsB[] = $X2; $BoundsB[] = $Y;

         $LastY = $Y;
         $LastX1 = $X1; $LastX2 = $X2;

         $Y = $Y + $YStep;
        }
       $Bounds = array_merge($BoundsA,$this->reversePlots($BoundsB));
       $this->drawPolygonChart($Bounds,array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"Alpha"=>$AreaAlpha));

       for($i=0;$i<=count($BoundsA)-4;$i=$i+2)
        {
         $this->drawLine($BoundsA[$i],$BoundsA[$i+1],$BoundsA[$i+2],$BoundsA[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
         $this->drawLine($BoundsB[$i],$BoundsB[$i+1],$BoundsB[$i+2],$BoundsB[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
        }
      }
    }

   /* Draw a step chart */
   function drawStepChart($Format=NULL)
    {
     $BreakVoid		= isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : FALSE;
     $ReCenter		= isset($Format["ReCenter"]) ? $Format["ReCenter"] : TRUE;
     $VoidTicks		= isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
     $BreakR		= isset($Format["BreakR"]) ? $Format["BreakR"] : NULL;
     $BreakG		= isset($Format["BreakG"]) ? $Format["BreakG"] : NULL;
     $BreakB		= isset($Format["BreakB"]) ? $Format["BreakB"] : NULL;
     $DisplayValues	= isset($Format["DisplayValues"]) ? $Format["DisplayValues"] :FALSE;
     $DisplayOffset	= isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
     $DisplayColor	= isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
     $DisplayR		= isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
     $DisplayG		= isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
     $DisplayB		= isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
     $RecordImageMap	= isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
     $ImageMapPlotSize  = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;

     $Data = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];

         if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }

         if ( $BreakR == NULL )
          $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
         else
          $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);

         if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }

         $AxisID	= $Serie["Axis"];
         $Mode		= $Data["Axis"][$AxisID]["Display"];
         $Format	= $Data["Axis"][$AxisID]["Format"];
         $Unit		= $Data["Axis"][$AxisID]["Unit"];
         $Color		= array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);

         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));

         $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
           $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           $LastGoodY = NULL; $LastGoodX = NULL; $Init = FALSE;
           foreach($PosArray as $Key => $Y)
            {
             if ( $DisplayValues && $Serie["Data"][$Key] != VOID ) 
              {
               if ( $Y <= $LastY ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
               $this->drawText($X,$Y-$Offset-$Weight,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
              }

             if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
              {
               $this->drawLine($LastX,$LastY,$X,$LastY,$Color);
               $this->drawLine($X,$LastY,$X,$Y,$Color);
               if ( $ReCenter && $X+$XStep < $this->GraphAreaX2 - $XMargin )
                {
                 $this->drawLine($X,$Y,$X+$XStep,$Y,$Color);
                 if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X-$ImageMapPlotSize).",".floor($Y-$ImageMapPlotSize).",".floor($X+$XStep+$ImageMapPlotSize).",".floor($Y+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
                }
               else
                { if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastX-$ImageMapPlotSize).",".floor($LastY-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($LastY+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); } }
              }

             if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
              { 
               if ( $ReCenter )
                {
                 $this->drawLine($LastGoodX+$XStep,$LastGoodY,$X,$LastGoodY,$BreakSettings);
                 if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastGoodX+$XStep-$ImageMapPlotSize).",".floor($LastGoodY-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($LastGoodY+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
                }
               else
                {
                 $this->drawLine($LastGoodX,$LastGoodY,$X,$LastGoodY,$BreakSettings);
                 if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastGoodX-$ImageMapPlotSize).",".floor($LastGoodY-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($LastGoodY+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
                }

               $this->drawLine($X,$LastGoodY,$X,$Y,$BreakSettings);
               $LastGoodY = NULL;
              }
             elseif( !$BreakVoid && $LastGoodY == NULL && $Y != VOID )
              {
              $this->drawLine($this->GraphAreaX1 + $XMargin,$Y,$X,$Y,$BreakSettings);
               if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($this->GraphAreaX1+$XMargin-$ImageMapPlotSize).",".floor($Y-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($Y+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
              }

             if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
             if ( $Y == VOID ) { $Y = NULL; }

             if ( !$Init && $ReCenter ) { $X = $X - $XStep/2; $Init = TRUE; }
             $LastX = $X; $LastY = $Y;
             if ( $LastX < $this->GraphAreaX1 + $XMargin ) { $LastX = $this->GraphAreaX1 + $XMargin; }
             $X = $X + $XStep;
            }
           if ( $ReCenter )
            {
             $this->drawLine($LastX,$LastY,$this->GraphAreaX2 - $XMargin,$LastY,$Color);
             if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastX-$ImageMapPlotSize).",".floor($LastY-$ImageMapPlotSize).",".floor($this->GraphAreaX2-$XMargin+$ImageMapPlotSize).",".floor($LastY+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
            }
          }
         else
          {
           if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
           $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           $LastGoodY = NULL; $LastGoodX = NULL; $Init = FALSE;
           foreach($PosArray as $Key => $X)
            {
             if ( $DisplayValues && $Serie["Data"][$Key] != VOID ) 
              {
               if ( $X >= $LastX ) { $Align = TEXT_ALIGN_MIDDLELEFT; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_MIDDLERIGHT; $Offset = -$DisplayOffset; }
               $this->drawText($X+$Offset+$Weight,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
              }

             if ( $X != VOID && $LastX != NULL && $LastY != NULL )
              {
               $this->drawLine($LastX,$LastY,$LastX,$Y,$Color);
               $this->drawLine($LastX,$Y,$X,$Y,$Color);

               if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastX-$ImageMapPlotSize).",".floor($LastY-$ImageMapPlotSize).",".floor($LastX+$XStep+$ImageMapPlotSize).",".floor($Y+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
              }

             if ( $X != VOID && $LastX == NULL && $LastGoodY != NULL && !$BreakVoid )
              {
               $this->drawLine($LastGoodX,$LastGoodY,$LastGoodX,$LastGoodY+$YStep,$Color);
               if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastGoodX-$ImageMapPlotSize).",".floor($LastGoodY-$ImageMapPlotSize).",".floor($LastGoodX+$ImageMapPlotSize).",".floor($LastGoodY+$YStep+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }

               $this->drawLine($LastGoodX,$LastGoodY+$YStep,$LastGoodX,$Y,$BreakSettings);
               if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastGoodX-$ImageMapPlotSize).",".floor($LastGoodY+$YStep-$ImageMapPlotSize).",".floor($LastGoodX+$ImageMapPlotSize).",".floor($YStep+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }

               $this->drawLine($LastGoodX,$Y,$X,$Y,$BreakSettings);
               $LastGoodY = NULL;
              }
             elseif ( $X != VOID && $LastGoodY == NULL && !$BreakVoid )
              {
               $this->drawLine($X,$this->GraphAreaY1 + $XMargin,$X,$Y,$BreakSettings);
               if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X-$ImageMapPlotSize).",".floor($this->GraphAreaY1+$XMargin-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($Y+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
              }

             if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
             if ( $X == VOID ) { $X = NULL; }

             if ( !$Init && $ReCenter ) { $Y = $Y - $YStep/2; $Init = TRUE; }
             $LastX = $X; $LastY = $Y;
             if ( $LastY < $this->GraphAreaY1 + $XMargin ) { $LastY = $this->GraphAreaY1 + $XMargin; }
             $Y = $Y + $YStep;
            }
           if ( $ReCenter )
            {
             $this->drawLine($LastX,$LastY,$LastX,$this->GraphAreaY2 - $XMargin,$Color);
             if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastX-$ImageMapPlotSize).",".floor($LastY-$ImageMapPlotSize).",".floor($LastX+$ImageMapPlotSize).",".floor($this->GraphAreaY2-$XMargin+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
            }
          }
        }
      }
    }

   /* Draw a step chart */
   function drawFilledStepChart($Format=NULL)
    {
     $ReCenter		= isset($Format["ReCenter"]) ? $Format["ReCenter"] : TRUE;
     $DisplayValues	= isset($Format["DisplayValues"]) ? $Format["DisplayValues"] :FALSE;
     $DisplayOffset	= isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
     $DisplayColor	= isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
     $ForceTransparency	= isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : NULL;
     $DisplayR		= isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
     $DisplayG		= isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
     $DisplayB		= isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
     $AroundZero	= isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;

     $Data = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];

         if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }

         $AxisID	= $Serie["Axis"];
         $Mode		= $Data["Axis"][$AxisID]["Display"];
         $Format	= $Data["Axis"][$AxisID]["Format"];
         $Unit		= $Data["Axis"][$AxisID]["Unit"];

         $Color		= array("R"=>$R,"G"=>$G,"B"=>$B);
         if ( $ForceTransparency != NULL ) { $Color["Alpha"] = $ForceTransparency; } else { $Color["Alpha"] = $Alpha; }

         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
         $YZero    = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));

         $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
           if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }

           if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
           $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;

           if ( !$AroundZero ) { $YZero = $this->GraphAreaY2-1; }

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           $LastGoodY = NULL; $LastGoodX = NULL; $Points = ""; $Init = FALSE;
           foreach($PosArray as $Key => $Y)
            {
             if ( $Y == VOID && $LastX != NULL && $LastY != NULL && $Points !="" )
              {
               $Points[] = $LastX; $Points[] = $LastY;
               $Points[] = $X; $Points[] = $LastY;
               $Points[] = $X; $Points[] = $YZero;
               $this->drawPolygon($Points,$Color);
               $Points = "";
              }

             if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
              {
               if ( $Points == "") { $Points[] = $LastX; $Points[] = $YZero; }
               $Points[] = $LastX; $Points[] = $LastY;
               $Points[] = $X; $Points[] = $LastY;
               $Points[] = $X; $Points[] = $Y;
              }

             if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
             if ( $Y == VOID ) { $Y = NULL; }

             if ( !$Init && $ReCenter ) { $X = $X - $XStep/2; $Init = TRUE; }
             $LastX = $X; $LastY = $Y;
             if ( $LastX < $this->GraphAreaX1 + $XMargin ) { $LastX = $this->GraphAreaX1 + $XMargin; }
             $X = $X + $XStep;
            }

           if ( $ReCenter )
            {
             $Points[] = $LastX+$XStep/2; $Points[] = $LastY;
             $Points[] = $LastX+$XStep/2; $Points[] = $YZero;
            }
           else
            { $Points[] = $LastX; $Points[] = $YZero; }

           $this->drawPolygon($Points,$Color);
          }
         else
          {
           if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
           if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }

           if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
           $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           $LastGoodY = NULL; $LastGoodX = NULL; $Points = "";
           foreach($PosArray as $Key => $X)
            {
             if ( $X == VOID && $LastX != NULL && $LastY != NULL && $Points !="" )
              {
               $Points[] = $LastX; $Points[] = $LastY;
               $Points[] = $LastX; $Points[] = $Y;
               $Points[] = $YZero; $Points[] = $Y;
               $this->drawPolygon($Points,$Color);
               $Points = "";
              }

             if ( $X != VOID && $LastX != NULL && $LastY != NULL )
              {
               if ( $Points == "") { $Points[] = $YZero; $Points[] = $LastY; }
               $Points[] = $LastX; $Points[] = $LastY;
               $Points[] = $LastX; $Points[] = $Y;
               $Points[] = $X; $Points[] = $Y;
              }

             if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
             if ( $X == VOID ) { $X = NULL; }

             if ( $LastX == NULL && $ReCenter ) { $Y = $Y - $YStep/2; }
             $LastX = $X; $LastY = $Y;
             if ( $LastY < $this->GraphAreaY1 + $XMargin ) { $LastY = $this->GraphAreaY1 + $XMargin; }
             $Y = $Y + $YStep;
            }

           if ( $ReCenter )
            {
             $Points[] = $LastX; $Points[] = $LastY+$YStep/2;
             $Points[] = $YZero; $Points[] = $LastY+$YStep/2;
            }
           else
            { $Points[] = $YZero; $Points[] = $LastY; }

           $this->drawPolygon($Points,$Color);
          }
        }
      }
    }

   /* Draw an area chart */
   function drawAreaChart($Format=NULL)
    {
     $DisplayValues	= isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
     $DisplayOffset	= isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
     $DisplayColor	= isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
     $DisplayR		= isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
     $DisplayG		= isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
     $DisplayB		= isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
     $ForceTransparency	= isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : 25;
     $AroundZero	= isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
     $Threshold		= isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;

     $Data  = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();

     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
         if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }

         $AxisID	= $Serie["Axis"];
         $Mode		= $Data["Axis"][$AxisID]["Display"];
         $Format	= $Data["Axis"][$AxisID]["Format"];
         $Unit		= $Data["Axis"][$AxisID]["Unit"];

         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
         $YZero    = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));

         if ( $Threshold != NULL )
          {
           foreach($Threshold as $Key => $Params)
            {
             $Threshold[$Key]["MinX"] = $this->scaleComputeY($Params["Min"],array("AxisID"=>$Serie["Axis"]));
             $Threshold[$Key]["MaxX"] = $this->scaleComputeY($Params["Max"],array("AxisID"=>$Serie["Axis"]));
            }
          }

         $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }

           $Areas = ""; $AreaID = 0; 
           $Areas[$AreaID][] = $this->GraphAreaX1 + $XMargin;
           if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }

           if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
           $X     = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           foreach($PosArray as $Key => $Y)
            {
             if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
              {
               if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
               $this->drawText($X,$Y-$Offset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
              }

             if ( $Y == VOID && isset($Areas[$AreaID]) )
              {
               if($LastX == NULL)
                { $Areas[$AreaID][] = $X; }
               else
                { $Areas[$AreaID][] = $LastX; }

               if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
               $AreaID++;
              }
             elseif ($Y != VOID)
              {
               if ( !isset($Areas[$AreaID]) )
                {
                 $Areas[$AreaID][] = $X;
                 if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
                }

               $Areas[$AreaID][] = $X;
               $Areas[$AreaID][] = $Y;
              }

             $LastX = $X;
             $X = $X + $XStep;
            }
           $Areas[$AreaID][] = $LastX;
           if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }

           $Alpha = $ForceTransparency != NULL ? $ForceTransparency : $Alpha;
           $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Threshold"=>$Threshold);
           foreach($Areas as $Key => $Points)
            $this->drawPolygonChart($Points,$Color);
          }
         else
          {
           if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
           if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }

           $Areas = ""; $AreaID = 0; 
           if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
           $Areas[$AreaID][] = $this->GraphAreaY1 + $XMargin;

           if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
           $Y     = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           foreach($PosArray as $Key => $X)
            {
             if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
              {
               if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
               $this->drawText($X+$Offset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
              }

             if ( $X == VOID && isset($Areas[$AreaID]) )
              {
               if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }

               if($LastY == NULL)
                { $Areas[$AreaID][] = $Y; }
               else
                { $Areas[$AreaID][] = $LastY; }

               $AreaID++;
              }
             elseif ($X != VOID)
              {
               if ( !isset($Areas[$AreaID]) )
                {
                 if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
                 $Areas[$AreaID][] = $Y;
                }

               $Areas[$AreaID][] = $X;
               $Areas[$AreaID][] = $Y;
              }

             $LastX = $X; $LastY = $Y;
             $Y = $Y + $YStep;
            }
           if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
           $Areas[$AreaID][] = $LastY;

           $Alpha = $ForceTransparency != NULL ? $ForceTransparency : $Alpha;
           $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Threshold"=>$Threshold);
           foreach($Areas as $Key => $Points)
            $this->drawPolygonChart($Points,$Color);
          }
        }
      }
    }


   /* Draw a bar chart */
   function drawBarChart($Format=NULL)
    {
     $Floating0Serie	= isset($Format["Floating0Serie"]) ? $Format["Floating0Serie"] : NULL;
     $Floating0Value	= isset($Format["Floating0Value"]) ? $Format["Floating0Value"] : NULL;
     $Draw0Line		= isset($Format["Draw0Line"]) ? $Format["Draw0Line"] : FALSE;
     $DisplayValues	= isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
     $DisplayOffset	= isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
     $DisplayColor	= isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
     $DisplayFont	= isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontName;
     $DisplaySize	= isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
     $DisplayPos	= isset($Format["DisplayPos"]) ? $Format["DisplayPos"] : LABEL_POS_OUTSIDE;
     $DisplayShadow	= isset($Format["DisplayShadow"]) ? $Format["DisplayShadow"] : TRUE;
     $DisplayR		= isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
     $DisplayG		= isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
     $DisplayB		= isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
     $AroundZero	= isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
     $Interleave	= isset($Format["Interleave"]) ? $Format["Interleave"] : .5;
     $Rounded		= isset($Format["Rounded"]) ? $Format["Rounded"] : FALSE;
     $RoundRadius	= isset($Format["RoundRadius"]) ? $Format["RoundRadius"] : 4;
     $Surrounding	= isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
     $Gradient		= isset($Format["Gradient"]) ? $Format["Gradient"] : FALSE;
     $GradientMode	= isset($Format["GradientMode"]) ? $Format["GradientMode"] : GRADIENT_SIMPLE;
     $GradientAlpha	= isset($Format["GradientAlpha"]) ? $Format["GradientAlpha"] : 20;
     $GradientStartR	= isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
     $GradientStartG	= isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
     $GradientStartB	= isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
     $GradientEndR	= isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 0;
     $GradientEndG	= isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 0;
     $GradientEndB	= isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 0;
     $TxtMargin		= isset($Format["TxtMargin"]) ? $Format["TxtMargin"] : 6;
     $OverrideColors	= isset($Format["OverrideColors"]) ? $Format["OverrideColors"] : NULL;
     $OverrideSurrounding = isset($Format["OverrideSurrounding"]) ? $Format["OverrideSurrounding"] : 30;
     $InnerSurrounding	= isset($Format["InnerSurrounding"]) ? $Format["InnerSurrounding"] : NULL;
     $InnerBorderR	= isset($Format["InnerBorderR"]) ? $Format["InnerBorderR"] : -1;
     $InnerBorderG	= isset($Format["InnerBorderG"]) ? $Format["InnerBorderG"] : -1;
     $InnerBorderB	= isset($Format["InnerBorderB"]) ? $Format["InnerBorderB"] : -1;
     $RecordImageMap	= isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;

     $Data = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();

     if ( $OverrideColors != NULL )
      {
       $OverrideColors = $this->validatePalette($OverrideColors,$OverrideSurrounding);
       $this->DataSet->saveExtendedData("Palette",$OverrideColors);
      }

     $RestoreShadow = $this->Shadow;

     $SeriesCount  = $this->countDrawableSeries();
     $CurrentSerie = 0;
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
         if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
         if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
         if ( $InnerSurrounding != NULL ) { $InnerBorderR = $R+$InnerSurrounding; $InnerBorderG = $G+$InnerSurrounding; $InnerBorderB = $B+$InnerSurrounding; }
         if ( $InnerBorderR == -1 ) { $InnerColor = NULL; } else { $InnerColor = array("R"=>$InnerBorderR,"G"=>$InnerBorderG,"B"=>$InnerBorderB); }
         $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB);

         $AxisID	= $Serie["Axis"];
         $Mode		= $Data["Axis"][$AxisID]["Display"];
         $Format	= $Data["Axis"][$AxisID]["Format"];
         $Unit		= $Data["Axis"][$AxisID]["Unit"];

         if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }

         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));

         if ( $Floating0Value != NULL )
          { $YZero = $this->scaleComputeY($Floating0Value,array("AxisID"=>$Serie["Axis"])); }
         else
          { $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"])); }

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
           if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }

           if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
           $X = $this->GraphAreaX1 + $XMargin;

           if ( $AroundZero ) { $Y1 = $YZero; } else { $Y1 = $this->GraphAreaY2-1; }
           if ( $XDivs == 0 ) { $XSize = ($this->GraphAreaX2-$this->GraphAreaX1)/($SeriesCount+$Interleave); } else { $XSize   = ($XStep / ($SeriesCount+$Interleave) ); }

           $XOffset = -($XSize*$SeriesCount)/2 + $CurrentSerie * $XSize;
           if ( $X + $XOffset <= $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $X + 1 ; }

           $this->DataSet->Data["Series"][$SerieName]["XOffset"] = $XOffset + $XSize / 2;

           if ( $Rounded || $BorderR != -1) { $XSpace = 1; } else { $XSpace = 0; }

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }

           $ID = 0;
           foreach($PosArray as $Key => $Y2)
            {
             if ( $Floating0Serie != NULL )
              {
               if ( isset($Data["Series"][$Floating0Serie]["Data"][$Key]) )
                { $Value = $Data["Series"][$Floating0Serie]["Data"][$Key]; }
               else
                { $Value = 0; }

               $YZero = $this->scaleComputeY($Value,array("AxisID"=>$Serie["Axis"]));
               if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
               if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }

               if ( $AroundZero ) { $Y1 = $YZero; } else { $Y1 = $this->GraphAreaY2-1; }
              }

             if ( $OverrideColors != NULL )
              { if ( isset($OverrideColors[$ID]) ) { $Color = array("R"=>$OverrideColors[$ID]["R"],"G"=>$OverrideColors[$ID]["G"],"B"=>$OverrideColors[$ID]["B"],"Alpha"=>$OverrideColors[$ID]["Alpha"],"BorderR"=>$OverrideColors[$ID]["BorderR"],"BorderG"=>$OverrideColors[$ID]["BorderG"],"BorderB"=>$OverrideColors[$ID]["BorderB"]); } else { $Color = $this->getRandomColor(); } }

             if ( $Y2 != VOID )
              {
               $BarHeight = $Y1 - $Y2;

               if ( $Serie["Data"][$Key] == 0 )
                $this->drawLine($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y1,$Color);
               else
                {
                 if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X+$XOffset+$XSpace).",".floor($Y1).",".floor($X+$XOffset+$XSize-$XSpace).",".floor($Y2),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }

                 if ( $Rounded )
                  $this->drawRoundedFilledRectangle($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,$RoundRadius,$Color);
                 else
                  {
                   $this->drawFilledRectangle($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,$Color);

                   if ( $InnerColor != NULL ) { $this->drawRectangle($X+$XOffset+$XSpace+1,min($Y1,$Y2)+1,$X+$XOffset+$XSize-$XSpace-1,max($Y1,$Y2)-1,$InnerColor); }

                   if ( $Gradient )
                    {
                     $this->Shadow  = FALSE;

                     if ( $GradientMode == GRADIENT_SIMPLE )
                      {
                       if ( $Serie["Data"][$Key] >= 0 )
                        $GradienColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
                       else
                        $GradienColor = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);

                       $this->drawGradientArea($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,DIRECTION_VERTICAL,$GradienColor);
                      }
                     elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
                      {
                       $GradienColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
                       $GradienColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
                       $XSpan = floor($XSize / 3);

                       $this->drawGradientArea($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSpan-$XSpace,$Y2,DIRECTION_HORIZONTAL,$GradienColor1);
                       $this->drawGradientArea($X+$XOffset+$XSpan+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,DIRECTION_HORIZONTAL,$GradienColor2);
                      }
                     $this->Shadow = $RestoreShadow;
                    }
                  }

                 if ( $Draw0Line )
                  {
                   $Line0Color = array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20);

                   if ( abs($Y1 - $Y2) > 3 ) { $Line0Width = 3; } else { $Line0Width = 1; }
                   if ( $Y1 - $Y2 < 0 ) { $Line0Width = -$Line0Width; }

                   $this->drawFilledRectangle($X+$XOffset+$XSpace,floor($Y1),$X+$XOffset+$XSize-$XSpace,floor($Y1)-$Line0Width,$Line0Color);
                   $this->drawLine($X+$XOffset+$XSpace,floor($Y1),$X+$XOffset+$XSize-$XSpace,floor($Y1),$Line0Color);
                  }
                }

               if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
                {
                 if ( $DisplayShadow ) { $this->Shadow = TRUE; }

                 $Caption    = $this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit);
                 $TxtPos     = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,90,$Caption);
                 $TxtHeight  = $TxtPos[0]["Y"] - $TxtPos[1]["Y"] + $TxtMargin;

                 if ( $DisplayPos == LABEL_POS_INSIDE && abs($TxtHeight) < abs($BarHeight) )
                  {
                   $CenterX = (($X+$XOffset+$XSize-$XSpace)-($X+$XOffset+$XSpace))/2 + $X+$XOffset+$XSpace;
                   $CenterY = ($Y2-$Y1)/2 + $Y1;

                   $this->drawText($CenterX,$CenterY,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"Angle"=>90));
                  }
                 else
                  {
                   if ( $Serie["Data"][$Key] >= 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
                   $this->drawText($X+$XOffset+$XSize/2,$Y2-$Offset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align,"FontSize"=>$DisplaySize));
                  }

                 $this->Shadow = $RestoreShadow;
                }
              }

             $X = $X + $XStep;
             $ID++;
            }
          }
         else
          {
           if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
           if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }

           if ( $XDivs == 0 ) { $YStep = 0; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
           
           $Y = $this->GraphAreaY1 + $XMargin;

           if ( $AroundZero ) { $X1 = $YZero; } else { $X1 = $this->GraphAreaX1+1; }
           if ( $XDivs == 0 ) { $YSize = ($this->GraphAreaY2-$this->GraphAreaY1)/($SeriesCount+$Interleave); } else { $YSize   = ($YStep / ($SeriesCount+$Interleave) ); }
           
           $YOffset = -($YSize*$SeriesCount)/2 + $CurrentSerie * $YSize;
           if ( $Y + $YOffset <= $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $Y + 1 ; }

           $this->DataSet->Data["Series"][$SerieName]["XOffset"] = $YOffset + $YSize / 2;

           if ( $Rounded || $BorderR != -1 ) { $YSpace = 1; } else { $YSpace = 0; }

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }

           $ID = 0 ;
           foreach($PosArray as $Key => $X2)
            {
             if ( $Floating0Serie != NULL )
              {
               if ( isset($Data["Series"][$Floating0Serie]["Data"][$Key]) )
                $Value = $Data["Series"][$Floating0Serie]["Data"][$Key];
               else { $Value = 0; }

               $YZero = $this->scaleComputeY($Value,array("AxisID"=>$Serie["Axis"]));
               if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
               if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
               if ( $AroundZero ) { $X1 = $YZero; } else { $X1 = $this->GraphAreaX1+1; }
              }

             if ( $OverrideColors != NULL )
              { if ( isset($OverrideColors[$ID]) ) { $Color = array("R"=>$OverrideColors[$ID]["R"],"G"=>$OverrideColors[$ID]["G"],"B"=>$OverrideColors[$ID]["B"],"Alpha"=>$OverrideColors[$ID]["Alpha"],"BorderR"=>$OverrideColors[$ID]["BorderR"],"BorderG"=>$OverrideColors[$ID]["BorderG"],"BorderB"=>$OverrideColors[$ID]["BorderB"]); } else { $Color = $this->getRandomColor(); } }

             if ( $X2 != VOID )
              {
               $BarWidth = $X2 - $X1;

               if ( $Serie["Data"][$Key] == 0 )
                $this->drawLine($X1,$Y+$YOffset+$YSpace,$X1,$Y+$YOffset+$YSize-$YSpace,$Color);
               else
                {
                 if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X1).",".floor($Y+$YOffset+$YSpace).",".floor($X2).",".floor($Y+$YOffset+$YSize-$YSpace),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }

                 if ( $Rounded )
                  $this->drawRoundedFilledRectangle($X1+1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,$RoundRadius,$Color);
                 else
                  {
                   $this->drawFilledRectangle($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,$Color);

                   if ( $InnerColor != NULL ) { $this->drawRectangle(min($X1,$X2)+1,$Y+$YOffset+$YSpace+1,max($X1,$X2)-1,$Y+$YOffset+$YSize-$YSpace-1,$InnerColor); }

                   if ( $Gradient )
                    {
                     $this->Shadow  = FALSE;

                     if ( $GradientMode == GRADIENT_SIMPLE )
                      {
                       if ( $Serie["Data"][$Key] >= 0 )
                        $GradienColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
                       else
                        $GradienColor = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);

                       $this->drawGradientArea($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,DIRECTION_HORIZONTAL,$GradienColor);
                      }
                     elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
                      {
                       $GradienColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
                       $GradienColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
                       $YSpan = floor($YSize / 3);

                       $this->drawGradientArea($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSpan-$YSpace,DIRECTION_VERTICAL,$GradienColor1);
                       $this->drawGradientArea($X1,$Y+$YOffset+$YSpan,$X2,$Y+$YOffset+$YSize-$YSpace,DIRECTION_VERTICAL,$GradienColor2);
                      }
                     $this->Shadow = $RestoreShadow;
                    }
                  }

                 if ( $Draw0Line )
                  {
                   $Line0Color = array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20);

                   if ( abs($X1 - $X2) > 3 ) { $Line0Width = 3; } else { $Line0Width = 1; }
                   if ( $X2 - $X1 < 0 ) { $Line0Width = -$Line0Width; }

                   $this->drawFilledRectangle(floor($X1),$Y+$YOffset+$YSpace,floor($X1)+$Line0Width,$Y+$YOffset+$YSize-$YSpace,$Line0Color);
                   $this->drawLine(floor($X1),$Y+$YOffset+$YSpace,floor($X1),$Y+$YOffset+$YSize-$YSpace,$Line0Color);
                  }
                }

               if ( $DisplayValues && $Serie["Data"][$Key] != VOID ) 
                {
                 if ( $DisplayShadow ) { $this->Shadow = TRUE; }

                 $Caption   = $this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit);
                 $TxtPos    = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
                 $TxtWidth  = $TxtPos[1]["X"] - $TxtPos[0]["X"] + $TxtMargin;

                 if ( $DisplayPos == LABEL_POS_INSIDE && abs($TxtWidth) < abs($BarWidth) )
                  {
                   $CenterX = ($X2-$X1)/2 + $X1;
                   $CenterY = (($Y+$YOffset+$YSize-$YSpace)-($Y+$YOffset+$YSpace))/2 + ($Y+$YOffset+$YSpace);

                   $this->drawText($CenterX,$CenterY,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize));
                  }
                 else
                  {
                   if ( $Serie["Data"][$Key] >= 0 ) { $Align = TEXT_ALIGN_MIDDLELEFT; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_MIDDLERIGHT; $Offset = -$DisplayOffset; }
                   $this->drawText($X2+$Offset,$Y+$YOffset+$YSize/2,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align,"FontSize"=>$DisplaySize));
                  }

                 $this->Shadow = $RestoreShadow;
                }
              }
             $Y = $Y + $YStep;
             $ID++;
            }
          }
         $CurrentSerie++;
        }
      }
    }

   /* Draw a bar chart */
   function drawStackedBarChart($Format=NULL)
    {
     $DisplayValues	= isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
     $DisplayRound      = isset($Format["DisplayRound"]) ? $Format["DisplayRound"] : 0;
     $DisplayColor	= isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
     $DisplayFont	= isset($Format["DisplayFont"]) ? $Format["DisplayFont"] : $this->FontName;
     $DisplaySize	= isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
     $DisplayR		= isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
     $DisplayG		= isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
     $DisplayB		= isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
     $Interleave	= isset($Format["Interleave"]) ? $Format["Interleave"] : .5;
     $Rounded		= isset($Format["Rounded"]) ? $Format["Rounded"] : FALSE;
     $RoundRadius	= isset($Format["RoundRadius"]) ? $Format["RoundRadius"] : 4;
     $Surrounding	= isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
     $Gradient		= isset($Format["Gradient"]) ? $Format["Gradient"] : FALSE;
     $GradientMode	= isset($Format["GradientMode"]) ? $Format["GradientMode"] : GRADIENT_SIMPLE;
     $GradientAlpha	= isset($Format["GradientAlpha"]) ? $Format["GradientAlpha"] : 20;
     $GradientStartR	= isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
     $GradientStartG	= isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
     $GradientStartB	= isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
     $GradientEndR	= isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 0;
     $GradientEndG	= isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 0;
     $GradientEndB	= isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 0;
     $InnerSurrounding	= isset($Format["InnerSurrounding"]) ? $Format["InnerSurrounding"] : NULL;
     $InnerBorderR	= isset($Format["InnerBorderR"]) ? $Format["InnerBorderR"] : -1;
     $InnerBorderG	= isset($Format["InnerBorderG"]) ? $Format["InnerBorderG"] : -1;
     $InnerBorderB	= isset($Format["InnerBorderB"]) ? $Format["InnerBorderB"] : -1;
     $RecordImageMap	= isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;

     $Data = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();

     $RestoreShadow = $this->Shadow;

     $LastX = ""; $LastY = "";
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
         if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = 255; $DisplayG = 255; $DisplayB = 255; }
         if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
         if ( $InnerSurrounding != NULL ) { $InnerBorderR = $R+$InnerSurrounding; $InnerBorderG = $G+$InnerSurrounding; $InnerBorderB = $B+$InnerSurrounding; }
         if ( $InnerBorderR == -1 ) { $InnerColor = NULL; } else { $InnerColor = array("R"=>$InnerBorderR,"G"=>$InnerBorderG,"B"=>$InnerBorderB); }

         $AxisID	= $Serie["Axis"];
         $Mode		= $Data["Axis"][$AxisID]["Display"];
         $Format	= $Data["Axis"][$AxisID]["Format"];
         $Unit		= $Data["Axis"][$AxisID]["Unit"];

         if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }

         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]),TRUE);
         $YZero    = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));

         $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;

         $Color = array("TransCorner"=>TRUE,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB);

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
           if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }

           if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
           $X     = $this->GraphAreaX1 + $XMargin;

           $XSize   = ($XStep / (1+$Interleave) );
           $XOffset = -($XSize/2);

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           foreach($PosArray as $Key => $Height)
            {
             if ( $Height != VOID && $Serie["Data"][$Key] != 0 )
              {
               if ( $Serie["Data"][$Key] > 0 ) { $Pos = "+"; } else { $Pos = "-"; }

               if ( !isset($LastY[$Key] ) ) { $LastY[$Key] = ""; }
               if ( !isset($LastY[$Key][$Pos] ) ) { $LastY[$Key][$Pos] = $YZero; }

               $Y1 = $LastY[$Key][$Pos];
               $Y2 = $Y1 - $Height;

               if ( ($Rounded || $BorderR != -1) && ($Pos == "+" && $Y1 != $YZero) ) { $YSpaceUp = 1; } else { $YSpaceUp = 0; }
               if ( ($Rounded || $BorderR != -1) && ($Pos == "-" && $Y1 != $YZero) ) { $YSpaceDown = 1; } else { $YSpaceDown = 0; }

               if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X+$XOffset).",".floor($Y1-$YSpaceUp+$YSpaceDown).",".floor($X+$XOffset+$XSize).",".floor($Y2),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }

               if ( $Rounded )
                $this->drawRoundedFilledRectangle($X+$XOffset,$Y1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2,$RoundRadius,$Color);
               else
                {
                 $this->drawFilledRectangle($X+$XOffset,$Y1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2,$Color);

                 if ( $InnerColor != NULL ) { $RestoreShadow = $this->Shadow; $this->Shadow = FALSE; $this->drawRectangle(min($X+$XOffset+1,$X+$XOffset+$XSize),min($Y1-$YSpaceUp+$YSpaceDown,$Y2)+1,max($X+$XOffset+1,$X+$XOffset+$XSize)-1,max($Y1-$YSpaceUp+$YSpaceDown,$Y2)-1,$InnerColor); $this->Shadow = $RestoreShadow;}

                 if ( $Gradient )
                  {
                   $this->Shadow  = FALSE;

                   if ( $GradientMode == GRADIENT_SIMPLE )
                    {
                     $GradientColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
                     $this->drawGradientArea($X+$XOffset-.5,$Y1-.5-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2+.5,DIRECTION_VERTICAL,$GradientColor);
                    }
                   elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
                    {
                     $GradientColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
                     $GradientColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
                     $XSpan = floor($XSize / 3);

                     $this->drawGradientArea($X+$XOffset-.5,$Y1-.5-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSpan,$Y2+.5,DIRECTION_HORIZONTAL,$GradientColor1);
                     $this->drawGradientArea($X+$XSpan+$XOffset-.5,$Y1-.5-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2+.5,DIRECTION_HORIZONTAL,$GradientColor2);
                    }
                   $this->Shadow = $RestoreShadow;
                  }
                }

               if ( $DisplayValues )
                {
                 $BarHeight = abs($Y2-$Y1);

                 $Caption   = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
                 $TxtPos    = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
                 $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);

                 if ( $BarHeight > $TxtHeight )
                  {
                   $XCenter = ( ($X+$XOffset+$XSize) - ($X+$XOffset) ) / 2 + $X+$XOffset;
                   $YCenter = ( ($Y2) - ($Y1-$YSpaceUp+$YSpaceDown) ) / 2 + $Y1-$YSpaceUp+$YSpaceDown;

                   $this->drawText($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
                  }
                }

               $LastY[$Key][$Pos] = $Y2;
              }

             $X = $X + $XStep;
            }
          }
         else
          {
           if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
           if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }

           if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
           $Y     = $this->GraphAreaY1 + $XMargin;

           $YSize   = $YStep / (1+$Interleave);
           $YOffset = -($YSize/2);

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           foreach($PosArray as $Key => $Width)
            {
             if ( $Width != VOID && $Serie["Data"][$Key] != 0 )
              {
               if ( $Serie["Data"][$Key] > 0 ) { $Pos = "+"; } else { $Pos = "-"; }

               if ( !isset($LastX[$Key] ) ) { $LastX[$Key] = ""; }
               if ( !isset($LastX[$Key][$Pos] ) ) { $LastX[$Key][$Pos] = $YZero; }

               $X1 = $LastX[$Key][$Pos];
               $X2 = $X1 + $Width;

               if ( ($Rounded || $BorderR != -1) && ($Pos == "+" && $X1 != $YZero) ) { $XSpaceLeft = 2; } else { $XSpaceLeft = 0; }
               if ( ($Rounded || $BorderR != -1) && ($Pos == "-" && $X1 != $YZero) ) { $XSpaceRight = 2; } else { $XSpaceRight = 0; }

               if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X1+$XSpaceLeft).",".floor($Y+$YOffset).",".floor($X2-$XSpaceRight).",".floor($Y+$YOffset+$YSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }

               if ( $Rounded )
                $this->drawRoundedFilledRectangle($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,$RoundRadius,$Color);
               else
                {
                 $this->drawFilledRectangle($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,$Color);

                 if ( $InnerColor != NULL ) { $RestoreShadow = $this->Shadow; $this->Shadow = FALSE; $this->drawRectangle(min($X1+$XSpaceLeft,$X2-$XSpaceRight)+1,min($Y+$YOffset,$Y+$YOffset+$YSize)+1,max($X1+$XSpaceLeft,$X2-$XSpaceRight)-1,max($Y+$YOffset,$Y+$YOffset+$YSize)-1,$InnerColor); $this->Shadow = $RestoreShadow;}

                 if ( $Gradient )
                  {
                   $this->Shadow  = FALSE;

                   if ( $GradientMode == GRADIENT_SIMPLE )
                    {
                     $GradientColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
                     $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,DIRECTION_HORIZONTAL,$GradientColor);
                    }
                   elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
                    {
                     $GradientColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
                     $GradientColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
                     $YSpan = floor($YSize / 3);

                     $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSpan,DIRECTION_VERTICAL,$GradientColor1);
                     $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset+$YSpan,$X2-$XSpaceRight,$Y+$YOffset+$YSize,DIRECTION_VERTICAL,$GradientColor2);
                    }
                   $this->Shadow = $RestoreShadow;
                  }
                }

               if ( $DisplayValues )
                {
                 $BarWidth = abs($X2-$X1);

                 $Caption   = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
                 $TxtPos    = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
                 $TxtWidth  = abs($TxtPos[1]["X"] - $TxtPos[0]["X"]);

                 if ( $BarWidth > $TxtWidth )
                  {
                   $XCenter  = ( $X2 - $X1 ) / 2 + $X1;
                   $YCenter  = ( ($Y+$YOffset+$YSize) - ($Y+$YOffset) ) / 2 + $Y+$YOffset;

                   $this->drawText($XCenter,$YCenter,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
                  }
                }

               $LastX[$Key][$Pos] = $X2;
              }

             $Y = $Y + $YStep;
            }
          }
        }
      }
    }

   /* Draw a bar chart */
   function drawStackedAreaChart($Format=NULL)
    {
     $DisplayValues	= isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
     $DisplayRound      = isset($Format["DisplayRound"]) ? $Format["DisplayRound"] : 0;
     $DisplayColor	= isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
     $DisplayFont	= isset($Format["DisplayFont"]) ? $Format["DisplayFont"] : $this->FontName;
     $DisplaySize	= isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
     $DisplayR		= isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
     $DisplayG		= isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
     $DisplayB		= isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
     $Surrounding	= isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
     $ForceTransparency	= isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : NULL;

     $Data = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();

     $RestoreShadow = $this->Shadow;

     /* Determine if we only have positive or negatives values */
     $Sign["+"] = 0; $Sign["-"] = 0;
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        { foreach($Serie["Data"] as $Key => $Value) { if ($Value > 0) { $Sign["+"]++; } elseif ($Value < 0) { $Sign["-"]++; } } }
      } 
     if ( $Sign["+"] == 0 || $Sign["-"] == 0 ) { $SingleWay = TRUE; } else { $SingleWay = FALSE; }

     $LastX = ""; $LastY = "";
     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];

         if ( $ForceTransparency != NULL ) { $Alpha = $ForceTransparency; }
         if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = 255; $DisplayG = 255; $DisplayB = 255; }
         if ( $Surrounding != NULL )
          { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
         else
          { $BorderR = $R; $BorderG = $G; $BorderB = $B; }

         $AxisID	= $Serie["Axis"];
         $Mode		= $Data["Axis"][$AxisID]["Display"];
         $Format	= $Data["Axis"][$AxisID]["Format"];
         $Unit		= $Data["Axis"][$AxisID]["Unit"];

         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]),TRUE);
         $YZero    = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));

         $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
           if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }

           $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB,"SkipY"=>$YZero);

           if ( $SingleWay ) { unset($Color["SkipY"]); }

           if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
           $X = $this->GraphAreaX1 + $XMargin;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }

           $PointsTop = ""; $PointsBottom = ""; $Labels = ""; $Pos = "+";
           foreach($PosArray as $Key => $Height)
            {
             if ( !isset($LastY[$Key] ) )       { $LastY[$Key] = ""; }
             if ( !isset($LastY[$Key][$Pos] ) ) { $LastY[$Key][$Pos] = $YZero; }

             if ( $Height != VOID && $Serie["Data"][$Key] >= 0)
              {
               $Y1 = $LastY[$Key][$Pos];
               $Y2 = $Y1 - $Height;

               $PointsTop[]    = $X; $PointsTop[]    = $Y2;
               $PointsBottom[] = $X; $PointsBottom[] = $Y1;

               if ( $DisplayValues )
                {
                 $BarHeight = abs($Y2-$Y1);

                 $Caption   = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
                 $TxtPos    = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
                 $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);

                 if ( $BarHeight > $TxtHeight )
                  {
                   $XCenter = $X;
                   $YCenter = $Y1- $BarHeight / 2;

                   $Labels[] = array($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
                  }
                }

               $LastY[$Key][$Pos] = $Y2;
              }
             else
              { $PointsTop[] = $X; $PointsTop[] = $LastY[$Key][$Pos]; $PointsBottom[] = $X; $PointsBottom[] = $LastY[$Key][$Pos]; }

             $X = $X + $XStep;
            }
           $Points = $PointsTop;
           for($i=count($PointsBottom)-2;$i>=0;$i-=2) { $Points[] = $PointsBottom[$i]; $Points[] = $PointsBottom[$i+1]; }
           $this->drawPolygon($Points,$Color);

           /* Reset the X axis parser for the negative values pass */
           $X = $this->GraphAreaX1 + $XMargin;

           $PointsTop = ""; $PointsBottom = ""; $Pos = "-";
           foreach($PosArray as $Key => $Height)
            {
             if ( !isset($LastY[$Key] ) )       { $LastY[$Key] = ""; }
             if ( !isset($LastY[$Key][$Pos] ) ) { $LastY[$Key][$Pos] = $YZero; }

             if ( $Height != VOID && $Serie["Data"][$Key] < 0)
              {
               $Y1 = $LastY[$Key][$Pos];
               $Y2 = $Y1 - $Height;

               $PointsTop[]    = $X; $PointsTop[]    = $Y2;
               $PointsBottom[] = $X; $PointsBottom[] = $Y1;

               if ( $DisplayValues )
                {
                 $BarHeight = abs($Y2-$Y1);

                 $Caption   = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
                 $TxtPos    = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
                 $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);

                 if ( $BarHeight > $TxtHeight )
                  {
                   $XCenter = $X;
                   $YCenter = $BarHeight / 2 + $Y1;

                   $Labels[] = array($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
                  }
                }

               $LastY[$Key][$Pos] = $Y2;
              }
             else
              { $PointsTop[] = $X; $PointsTop[] = $LastY[$Key][$Pos]; $PointsBottom[] = $X; $PointsBottom[] = $LastY[$Key][$Pos]; }

             $X = $X + $XStep;
            }
           $Points = $PointsTop;
           for($i=count($PointsBottom)-2;$i>=0;$i-=2) { $Points[] = $PointsBottom[$i]; $Points[] = $PointsBottom[$i+1]; }
           $this->drawPolygon($Points,$Color);

           if ( $DisplayValues ) { foreach($Labels as $Key => $Value) { $this->drawText($Value[0],$Value[1],$Value[2],$Value[3]);} }
          }
         else
          {
           if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
           if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }

           $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB,"SkipX"=>$YZero);

           if ( $SingleWay ) { unset($Color["SkipX"]); }

           if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
           $Y = $this->GraphAreaY1 + $XMargin;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }

           $PointsTop = ""; $PointsBottom = ""; $Labels = ""; $Pos = "+";
           foreach($PosArray as $Key => $Width)
            {
             if ( !isset($LastX[$Key] ) )       { $LastX[$Key] = ""; }
             if ( !isset($LastX[$Key][$Pos] ) ) { $LastX[$Key][$Pos] = $YZero; }

             if ( $Width != VOID && $Serie["Data"][$Key] >= 0)
              {
               $X1 = $LastX[$Key][$Pos];
               $X2 = $X1 + $Width;

               $PointsTop[]    = $X1; $PointsTop[]    = $Y;
               $PointsBottom[] = $X2; $PointsBottom[] = $Y;

               if ( $DisplayValues )
                {
                 $BarWidth = abs($X2-$X1);

                 $Caption   = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
                 $TxtPos    = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
                 $TxtWidth  = abs($TxtPos[1]["X"] - $TxtPos[0]["X"]);

                 if ( $BarWidth > $TxtWidth )
                  {
                   $XCenter  = $X1 + $BarWidth / 2;
                   $YCenter  = $Y;

                   $Labels[] = array($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
                  }
                }

               $LastX[$Key][$Pos] = $X2;
              }
             else
              { $PointsTop[] = $LastX[$Key][$Pos]; $PointsTop[] = $Y; $PointsBottom[] = $LastX[$Key][$Pos]; $PointsBottom[] = $Y; }

             $Y = $Y + $YStep;
            }
           $Points = $PointsTop;
           for($i=count($PointsBottom)-2;$i>=0;$i-=2) { $Points[] = $PointsBottom[$i]; $Points[] = $PointsBottom[$i+1]; }
           $this->drawPolygon($Points,$Color);


           /* Reset the X axis parser for the negative values pass */
           $Y = $this->GraphAreaY1 + $XMargin;


           $PointsTop = ""; $PointsBottom = ""; $Pos = "-";
           foreach($PosArray as $Key => $Width)
            {
             if ( !isset($LastX[$Key] ) )       { $LastX[$Key] = ""; }
             if ( !isset($LastX[$Key][$Pos] ) ) { $LastX[$Key][$Pos] = $YZero; }

             if ( $Width != VOID && $Serie["Data"][$Key] < 0)
              {
               $X1 = $LastX[$Key][$Pos];
               $X2 = $X1 + $Width;

               $PointsTop[]    = $X1; $PointsTop[]    = $Y;
               $PointsBottom[] = $X2; $PointsBottom[] = $Y;

               if ( $DisplayValues )
                {
                 $BarWidth = abs($X2-$X1);

                 $Caption   = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
                 $TxtPos    = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
                 $TxtWidth  = abs($TxtPos[1]["X"] - $TxtPos[0]["X"]);

                 if ( $BarWidth > $TxtWidth )
                  {
                   $XCenter  = $X1 - $BarWidth / 2;
                   $YCenter  = $Y;

                   $Labels[] = array($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
                  }
                }

               $LastX[$Key][$Pos] = $X2;
              }
             else
              { $PointsTop[] = $LastX[$Key][$Pos]; $PointsTop[] = $Y; $PointsBottom[] = $LastX[$Key][$Pos]; $PointsBottom[] = $Y; }

             $Y = $Y + $YStep;
            }
           $Points = $PointsTop;
           for($i=count($PointsBottom)-2;$i>=0;$i-=2) { $Points[] = $PointsBottom[$i]; $Points[] = $PointsBottom[$i+1]; }
           $this->drawPolygon($Points,$Color);

           if ( $DisplayValues ) { foreach($Labels as $Key => $Value) { $this->drawText($Value[0],$Value[1],$Value[2],$Value[3]);} }
          }
        }
      }
    }

   /* Returns a random color */
   function getRandomColor($Alpha=100)
    { return(array("R"=>rand(0,255),"G"=>rand(0,255),"B"=>rand(0,255),"Alpha"=>$Alpha)); }
 
   /* Validate a palette */
   function validatePalette($Colors,$Surrounding=NULL)
    {
     $Result = "";

     if ( !is_array($Colors) ) { return($this->getRandomColor()); }

     foreach($Colors as $Key => $Values)
      {
       if ( isset($Values["R"]) ) { $Result[$Key]["R"] = $Values["R"]; } else { $Result[$Key]["R"] = rand(0,255); }
       if ( isset($Values["G"]) ) { $Result[$Key]["G"] = $Values["G"]; } else { $Result[$Key]["G"] = rand(0,255); }
       if ( isset($Values["B"]) ) { $Result[$Key]["B"] = $Values["B"]; } else { $Result[$Key]["B"] = rand(0,255); }
       if ( isset($Values["Alpha"]) ) { $Result[$Key]["Alpha"] = $Values["Alpha"]; } else { $Result[$Key]["Alpha"] = 100; }

       if ( $Surrounding != NULL )
        {
         $Result[$Key]["BorderR"] = $Result[$Key]["R"] + $Surrounding;
         $Result[$Key]["BorderG"] = $Result[$Key]["G"] + $Surrounding;
         $Result[$Key]["BorderB"] = $Result[$Key]["B"] + $Surrounding;
        }
       else
        {
         if ( isset($Values["BorderR"]) )     { $Result[$Key]["BorderR"] = $Values["BorderR"]; } else { $Result[$Key]["BorderR"] = $Result[$Key]["R"]; }
         if ( isset($Values["BorderG"]) )     { $Result[$Key]["BorderG"] = $Values["BorderG"]; } else { $Result[$Key]["BorderG"] = $Result[$Key]["G"]; }
         if ( isset($Values["BorderB"]) )     { $Result[$Key]["BorderB"] = $Values["BorderB"]; } else { $Result[$Key]["BorderB"] = $Result[$Key]["B"]; }
         if ( isset($Values["BorderAlpha"]) ) { $Result[$Key]["BorderAlpha"] = $Values["BorderAlpha"]; } else { $Result[$Key]["BorderAlpha"] = $Result[$Key]["Alpha"]; }
        }
      }

     return($Result);
    }

   /* Draw the derivative chart associated to the data series */
   function drawDerivative($Format=NULL)
    {
     $Offset		= isset($Format["Offset"]) ? $Format["Offset"] : 10;
     $SerieSpacing	= isset($Format["SerieSpacing"]) ? $Format["SerieSpacing"] : 3;
     $DerivativeHeight	= isset($Format["DerivativeHeight"]) ? $Format["DerivativeHeight"] : 4;
     $ShadedSlopeBox	= isset($Format["ShadedSlopeBox"]) ? $Format["ShadedSlopeBox"] : FALSE;
     $DrawBackground	= isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : TRUE;
     $BackgroundR	= isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255;
     $BackgroundG	= isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255;
     $BackgroundB	= isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255;
     $BackgroundAlpha	= isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 20;
     $DrawBorder	= isset($Format["DrawBorder"]) ? $Format["DrawBorder"] : TRUE;
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : 0;
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : 0;
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : 0;
     $BorderAlpha	= isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 100;
     $Caption		= isset($Format["Caption"]) ? $Format["Caption"] : TRUE;
     $CaptionHeight	= isset($Format["CaptionHeight"]) ? $Format["CaptionHeight"] : 10;
     $CaptionWidth	= isset($Format["CaptionWidth"]) ? $Format["CaptionWidth"] : 20;
     $CaptionMargin	= isset($Format["CaptionMargin"]) ? $Format["CaptionMargin"] : 4;
     $CaptionLine	= isset($Format["CaptionLine"]) ? $Format["CaptionLine"] : FALSE;
     $CaptionBox	= isset($Format["CaptionBox"]) ? $Format["CaptionBox"] : FALSE;
     $CaptionBorderR	= isset($Format["CaptionBorderR"]) ? $Format["CaptionBorderR"] : 0;
     $CaptionBorderG	= isset($Format["CaptionBorderG"]) ? $Format["CaptionBorderG"] : 0;
     $CaptionBorderB	= isset($Format["CaptionBorderB"]) ? $Format["CaptionBorderB"] : 0;
     $CaptionFillR	= isset($Format["CaptionFillR"]) ? $Format["CaptionFillR"] : 255;
     $CaptionFillG	= isset($Format["CaptionFillG"]) ? $Format["CaptionFillG"] : 255;
     $CaptionFillB	= isset($Format["CaptionFillB"]) ? $Format["CaptionFillB"] : 255;
     $CaptionFillAlpha	= isset($Format["CaptionFillAlpha"]) ? $Format["CaptionFillAlpha"] : 80;
     $PositiveSlopeStartR	= isset($Format["PositiveSlopeStartR"]) ? $Format["PositiveSlopeStartR"] : 184;
     $PositiveSlopeStartG	= isset($Format["PositiveSlopeStartG"]) ? $Format["PositiveSlopeStartG"] : 234;
     $PositiveSlopeStartB	= isset($Format["PositiveSlopeStartB"]) ? $Format["PositiveSlopeStartB"] : 88;
     $PositiveSlopeEndR		= isset($Format["PositiveSlopeStartR"]) ? $Format["PositiveSlopeStartR"] : 239;
     $PositiveSlopeEndG		= isset($Format["PositiveSlopeStartG"]) ? $Format["PositiveSlopeStartG"] : 31;
     $PositiveSlopeEndB		= isset($Format["PositiveSlopeStartB"]) ? $Format["PositiveSlopeStartB"] : 36;
     $NegativeSlopeStartR	= isset($Format["NegativeSlopeStartR"]) ? $Format["NegativeSlopeStartR"] : 184;
     $NegativeSlopeStartG	= isset($Format["NegativeSlopeStartG"]) ? $Format["NegativeSlopeStartG"] : 234;
     $NegativeSlopeStartB	= isset($Format["NegativeSlopeStartB"]) ? $Format["NegativeSlopeStartB"] : 88;
     $NegativeSlopeEndR		= isset($Format["NegativeSlopeStartR"]) ? $Format["NegativeSlopeStartR"] : 67;
     $NegativeSlopeEndG		= isset($Format["NegativeSlopeStartG"]) ? $Format["NegativeSlopeStartG"] : 124;
     $NegativeSlopeEndB		= isset($Format["NegativeSlopeStartB"]) ? $Format["NegativeSlopeStartB"] : 227;

     $Data = $this->DataSet->getData();

     list($XMargin,$XDivs) = $this->scaleGetXSettings();

     if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
      $YPos = $this->DataSet->Data["GraphArea"]["Y2"] + $Offset;
     else
      $XPos = $this->DataSet->Data["GraphArea"]["X2"] + $Offset;

     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];

         $AxisID   = $Serie["Axis"];
         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           if ( $Caption )
            {
             if ( $CaptionLine ) 
              {
               $StartX = floor($this->GraphAreaX1-$CaptionWidth+$XMargin-$CaptionMargin);
               $EndX   = floor($this->GraphAreaX1-$CaptionMargin+$XMargin);

               $CaptionSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
               if ( $CaptionBox ) { $this->drawFilledRectangle($StartX,$YPos,$EndX,$YPos+$CaptionHeight,array("R"=>$CaptionFillR,"G"=>$CaptionFillG,"B"=>$CaptionFillB,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB,"Alpha"=>$CaptionFillAlpha)); }
               $this->drawLine($StartX+2,$YPos+($CaptionHeight/2),$EndX-2,$YPos+($CaptionHeight/2),$CaptionSettings);
              }
             else
              $this->drawFilledRectangle($this->GraphAreaX1-$CaptionWidth+$XMargin-$CaptionMargin,$YPos,$this->GraphAreaX1-$CaptionMargin+$XMargin,$YPos+$CaptionHeight,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB));
            }

           if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
           $X = $this->GraphAreaX1 + $XMargin;

           $TopY    = $YPos + ($CaptionHeight/2) - ($DerivativeHeight/2);
           $BottomY = $YPos + ($CaptionHeight/2) + ($DerivativeHeight/2);

           $StartX  = floor($this->GraphAreaX1+$XMargin);
           $EndX    = floor($this->GraphAreaX2-$XMargin);

           if ( $DrawBackground ) { $this->drawFilledRectangle($StartX-1,$TopY-1,$EndX+1,$BottomY+1,array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha)); }
           if ( $DrawBorder ) { $this->drawRectangle($StartX-1,$TopY-1,$EndX+1,$BottomY+1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }

           $RestoreShadow = $this->Shadow;
           $this->Shadow  = FALSE;

           /* Determine the Max slope index */
           $LastX = NULL; $LastY = NULL; $MinSlope = 0; $MaxSlope = 1;
           foreach($PosArray as $Key => $Y)
            {
             if ( $Y != VOID && $LastX != NULL )
              { $Slope = ($LastY - $Y); if ( $Slope > $MaxSlope ) { $MaxSlope = $Slope; } if ( $Slope < $MinSlope ) { $MinSlope = $Slope; } }

             if ( $Y == VOID )
              { $LastX = NULL; $LastY = NULL; }
             else
              { $LastX = $X; $LastY = $Y; }
            }

           $LastX = NULL; $LastY = NULL; $LastColor = NULL;
           foreach($PosArray as $Key => $Y)
            {
             if ( $Y != VOID && $LastY != NULL )
              {
               $Slope = ($LastY - $Y);

               if ( $Slope >= 0 )
                {
                 $SlopeIndex = (100 / $MaxSlope) * $Slope;
                 $R = (($PositiveSlopeEndR - $PositiveSlopeStartR)/100)*$SlopeIndex+$PositiveSlopeStartR;
                 $G = (($PositiveSlopeEndG - $PositiveSlopeStartG)/100)*$SlopeIndex+$PositiveSlopeStartG;
                 $B = (($PositiveSlopeEndB - $PositiveSlopeStartB)/100)*$SlopeIndex+$PositiveSlopeStartB;
                }
               elseif ( $Slope < 0 )
                {
                 $SlopeIndex = (100 / abs($MinSlope)) * abs($Slope);
                 $R = (($NegativeSlopeEndR - $NegativeSlopeStartR)/100)*$SlopeIndex+$NegativeSlopeStartR;
                 $G = (($NegativeSlopeEndG - $NegativeSlopeStartG)/100)*$SlopeIndex+$NegativeSlopeStartG;
                 $B = (($NegativeSlopeEndB - $NegativeSlopeStartB)/100)*$SlopeIndex+$NegativeSlopeStartB;
                }

               $Color = array("R"=>$R,"G"=>$G,"B"=>$B);

               if ( $ShadedSlopeBox && $LastColor != NULL ) // && $Slope != 0
                {
                 $GradientSettings = array("StartR"=>$LastColor["R"],"StartG"=>$LastColor["G"],"StartB"=>$LastColor["B"],"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
                 $this->drawGradientArea($LastX,$TopY,$X,$BottomY,DIRECTION_HORIZONTAL,$GradientSettings);
                }
               elseif ( !$ShadedSlopeBox || $LastColor == NULL ) // || $Slope == 0
                $this->drawFilledRectangle(floor($LastX),$TopY,floor($X),$BottomY,$Color);

               $LastColor = $Color;
              }

             if ( $Y == VOID )
              { $LastY = NULL; }
             else
              { $LastX = $X; $LastY = $Y; }

             $X = $X + $XStep;
            }

           $YPos = $YPos + $CaptionHeight + $SerieSpacing;
          }
         else
          {
           if ( $Caption )
            {
             $StartY = floor($this->GraphAreaY1-$CaptionWidth+$XMargin-$CaptionMargin);
             $EndY   = floor($this->GraphAreaY1-$CaptionMargin+$XMargin);
             if ( $CaptionLine ) 
              {
               $CaptionSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
               if ( $CaptionBox ) { $this->drawFilledRectangle($XPos,$StartY,$XPos+$CaptionHeight,$EndY,array("R"=>$CaptionFillR,"G"=>$CaptionFillG,"B"=>$CaptionFillB,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB,"Alpha"=>$CaptionFillAlpha)); }
               $this->drawLine($XPos+($CaptionHeight/2),$StartY+2,$XPos+($CaptionHeight/2),$EndY-2,$CaptionSettings);
              }
             else
              $this->drawFilledRectangle($XPos,$StartY,$XPos+$CaptionHeight,$EndY,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB));
            }


           if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
           $Y = $this->GraphAreaY1 + $XMargin;

           $TopX    = $XPos + ($CaptionHeight/2) - ($DerivativeHeight/2);
           $BottomX = $XPos + ($CaptionHeight/2) + ($DerivativeHeight/2);

           $StartY  = floor($this->GraphAreaY1+$XMargin);
           $EndY    = floor($this->GraphAreaY2-$XMargin);

           if ( $DrawBackground ) { $this->drawFilledRectangle($TopX-1,$StartY-1,$BottomX+1,$EndY+1,array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha)); }
           if ( $DrawBorder ) { $this->drawRectangle($TopX-1,$StartY-1,$BottomX+1,$EndY+1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }

           $RestoreShadow = $this->Shadow;
           $this->Shadow  = FALSE;

           /* Determine the Max slope index */
           $LastX = NULL; $LastY = NULL; $MinSlope = 0; $MaxSlope = 1;
           foreach($PosArray as $Key => $X)
            {
             if ( $X != VOID && $LastX != NULL )
              { $Slope = ($X - $LastX); if ( $Slope > $MaxSlope ) { $MaxSlope = $Slope; } if ( $Slope < $MinSlope ) { $MinSlope = $Slope; } }

             if ( $X == VOID )
              { $LastX = NULL; }
             else
              { $LastX = $X; }
            }

           $LastX = NULL; $LastY = NULL; $LastColor = NULL;
           foreach($PosArray as $Key => $X)
            {
             if ( $X != VOID && $LastX != NULL )
              {
               $Slope = ($X - $LastX);

               if ( $Slope >= 0 )
                {
                 $SlopeIndex = (100 / $MaxSlope) * $Slope;
                 $R = (($PositiveSlopeEndR - $PositiveSlopeStartR)/100)*$SlopeIndex+$PositiveSlopeStartR;
                 $G = (($PositiveSlopeEndG - $PositiveSlopeStartG)/100)*$SlopeIndex+$PositiveSlopeStartG;
                 $B = (($PositiveSlopeEndB - $PositiveSlopeStartB)/100)*$SlopeIndex+$PositiveSlopeStartB;
                }
               elseif ( $Slope < 0 )
                {
                 $SlopeIndex = (100 / abs($MinSlope)) * abs($Slope);
                 $R = (($NegativeSlopeEndR - $NegativeSlopeStartR)/100)*$SlopeIndex+$NegativeSlopeStartR;
                 $G = (($NegativeSlopeEndG - $NegativeSlopeStartG)/100)*$SlopeIndex+$NegativeSlopeStartG;
                 $B = (($NegativeSlopeEndB - $NegativeSlopeStartB)/100)*$SlopeIndex+$NegativeSlopeStartB;
                }

               $Color = array("R"=>$R,"G"=>$G,"B"=>$B);

               if ( $ShadedSlopeBox && $LastColor != NULL )
                {
                 $GradientSettings = array("StartR"=>$LastColor["R"],"StartG"=>$LastColor["G"],"StartB"=>$LastColor["B"],"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);

                 $this->drawGradientArea($TopX,$LastY,$BottomX,$Y,DIRECTION_VERTICAL,$GradientSettings);
                }
               elseif ( !$ShadedSlopeBox || $LastColor == NULL ) 
                $this->drawFilledRectangle($TopX,floor($LastY),$BottomX,floor($Y),$Color);

               $LastColor = $Color;
              }

             if ( $X == VOID )
              { $LastX = NULL; }
             else
              { $LastX = $X; $LastY = $Y; }

             $Y = $Y + $XStep;
            }

           $XPos = $XPos + $CaptionHeight + $SerieSpacing;
          }

         $this->Shadow = $RestoreShadow;
        }
      }
    }

   /* Draw the line of best fit */
   function drawBestFit($Format="")
    {
     $OverrideTicks	= isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
     $OverrideR		= isset($Format["R"]) ? $Format["R"] : VOID;
     $OverrideG		= isset($Format["G"]) ? $Format["G"] : VOID;
     $OverrideB		= isset($Format["B"]) ? $Format["B"] : VOID;
     $OverrideAlpha	= isset($Format["Alpha"]) ? $Format["Alpha"] : VOID;

     $Data = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();

     foreach($Data["Series"] as $SerieName => $Serie)
      {
       if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
        {
         if ( $OverrideR != VOID && $OverrideG != VOID && $OverrideB != VOID ) { $R = $OverrideR; $G = $OverrideG; $B = $OverrideB; } else { $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; }
         if ( $OverrideTicks == NULL ) { $Ticks = $Serie["Ticks"]; } else { $Ticks = $OverrideTicks; }
         if ( $OverrideAlpha == VOID ) { $Alpha = $Serie["Color"]["Alpha"]; } else { $Alpha = $OverrideAlpha; }

         $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks);

         $AxisID   = $Serie["Axis"];
         $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));

         if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
          {
           if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
           $X = $this->GraphAreaX1 + $XMargin;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           $Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
           foreach($PosArray as $Key => $Y)
            {
             $Sxy = $Sxy + $X*$Y;
             $Sx  = $Sx + $X;
             $Sy  = $Sy + $Y;
             $Sxx = $Sxx + $X*$X;

             $X = $X + $XStep;
            }
           $n = count($PosArray);
           $M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
           $B = (($Sy)-($M*$Sx))/($n);

           $X1 = $this->GraphAreaX1 + $XMargin;
           $Y1 = $M * $X1 + $B;
           $X2 = $this->GraphAreaX2 - $XMargin;
           $Y2 = $M * $X2 + $B;

           if ( $Y1 < $this->GraphAreaY1 ) { $X1 = $X1 + ($this->GraphAreaY1-$Y1); $Y1 = $this->GraphAreaY1; }
           if ( $Y1 > $this->GraphAreaY2 ) { $X1 = $X1 + ($Y1-$this->GraphAreaY2); $Y1 = $this->GraphAreaY2; }
           if ( $Y2 < $this->GraphAreaY1 ) { $X2 = $X2 - ($this->GraphAreaY1-$Y2); $Y2 = $this->GraphAreaY1; }
           if ( $Y2 > $this->GraphAreaY2 ) { $X2 = $X2 - ($Y2-$this->GraphAreaY2); $Y2 = $this->GraphAreaY2; }

           $this->drawLine($X1,$Y1,$X2,$Y2,$Color);
          }
         else
          {
           if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
           $Y = $this->GraphAreaY1 + $XMargin;

           if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
           $Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
           foreach($PosArray as $Key => $X)
            {
             $Sxy = $Sxy + $X*$Y;
             $Sx  = $Sx + $Y;
             $Sy  = $Sy + $X;
             $Sxx = $Sxx + $Y*$Y;

             $Y = $Y + $YStep;
            }
           $n = count($PosArray);
           $M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
           $B = (($Sy)-($M*$Sx))/($n);

           $Y1 = $this->GraphAreaY1 + $XMargin;
           $X1 = $M * $Y1 + $B;
           $Y2 = $this->GraphAreaY2 - $XMargin;
           $X2 = $M * $Y2 + $B;

           if ( $X1 < $this->GraphAreaX1 ) { $Y1 = $Y1 + ($this->GraphAreaX1-$X1); $X1 = $this->GraphAreaX1; }
           if ( $X1 > $this->GraphAreaX2 ) { $Y1 = $Y1 + ($X1-$this->GraphAreaX2); $X1 = $this->GraphAreaX2; }
           if ( $X2 < $this->GraphAreaX1 ) { $Y2 = $Y2 - ($this->GraphAreaY1-$X2); $X2 = $this->GraphAreaX1; }
           if ( $X2 > $this->GraphAreaX2 ) { $Y2 = $Y2 - ($X2-$this->GraphAreaX2); $X2 = $this->GraphAreaX2; }

           $this->drawLine($X1,$Y1,$X2,$Y2,$Color);
          }
        }
      }
    }

   /* Write labels */
   function writeLabel($SeriesName,$Indexes,$Format="")
    {
     $OverrideTitle	= isset($Format["OverrideTitle"]) ? $Format["OverrideTitle"] : NULL;
     $ForceLabels	= isset($Format["ForceLabels"]) ? $Format["ForceLabels"] : NULL;
     $DrawPoint		= isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX;
     $DrawVerticalLine	= isset($Format["DrawVerticalLine"]) ? $Format["DrawVerticalLine"] : FALSE;
     $VerticalLineR	= isset($Format["VerticalLineR"]) ? $Format["VerticalLineR"] : 0;
     $VerticalLineG	= isset($Format["VerticalLineG"]) ? $Format["VerticalLineG"] : 0;
     $VerticalLineB	= isset($Format["VerticalLineB"]) ? $Format["VerticalLineB"] : 0;
     $VerticalLineAlpha	= isset($Format["VerticalLineAlpha"]) ? $Format["VerticalLineAlpha"] : 40;
     $VerticalLineTicks	= isset($Format["VerticalLineTicks"]) ? $Format["VerticalLineTicks"] : 2;

     $Data = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();

     if ( !is_array($Indexes) )    { $Index = $Indexes; $Indexes = ""; $Indexes[] = $Index; }
     if ( !is_array($SeriesName) ) { $SerieName = $SeriesName; $SeriesName = ""; $SeriesName[] = $SerieName; }
     if ( $ForceLabels != NULL && !is_array($ForceLabels) ) { $ForceLabel = $ForceLabels; $ForceLabels = ""; $ForceLabels[] = $ForceLabel; }

     foreach ($Indexes as $Key => $Index)
      {
       $Series = "";

       if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
        {
         if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
         $X = $this->GraphAreaX1 + $XMargin + $Index * $XStep;

         if ( $DrawVerticalLine ) { $this->drawLine($X,$this->GraphAreaY1+$Data["YMargin"],$X,$this->GraphAreaY2-$Data["YMargin"],array("R"=>$VerticalLineR,"G"=>$VerticalLineG,"B"=>$VerticalLineB,"Alpha"=>$VerticalLineAlpha,"Ticks"=>$VerticalLineTicks)); }

         $MinY = $this->GraphAreaY2;
         foreach ($SeriesName as $iKey => $SerieName)
          {
           if ( isset($Data["Series"][$SerieName]["Data"][$Index]) )
            {
             $AxisID      = $Data["Series"][$SerieName]["Axis"];

             if ( $OverrideTitle != NULL)
              $Description = $OverrideTitle;
             elseif ( count($SeriesName) == 1 )
              {
               if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
                $Description = $Data["Series"][$SerieName]["Description"]." - ".$Data["Series"][$Data["Abscissa"]]["Data"][$Index];
               else
                $Description = $Data["Series"][$SerieName]["Description"];
              }
             elseif ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
              $Description = $Data["Series"][$Data["Abscissa"]]["Data"][$Index];

             $AxisMode     = $Data["Axis"][$AxisID]["Display"];
             $AxisFormat   = $Data["Axis"][$AxisID]["Format"];
             $AxisUnit     = $Data["Axis"][$AxisID]["Unit"];

             $Serie = "";
             $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
             $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
             $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
             $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];

             if ( count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"]) )
              $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
             else
              $SerieOffset = 0;

             $Value = $Data["Series"][$SerieName]["Data"][$Index];
             if ( $ForceLabels != NULL )
              $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
             else
              $Caption     = $this->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);

             $X = floor($this->GraphAreaX1 + $XMargin + $Index * $XStep + $SerieOffset);
             $Y = floor($this->scaleComputeY($Value,array("AxisID"=>$AxisID)));

             if ($Y < $MinY) { $MinY = $Y; }

             if ( $DrawPoint == LABEL_POINT_CIRCLE )
              $this->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
             elseif ( $DrawPoint == LABEL_POINT_BOX )
              $this->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));

             $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
            }
          }
         $this->drawLabelBox($X,$MinY-3,$Description,$Series,$Format);

        }
       else
        {
         if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
         $Y = $this->GraphAreaY1 + $XMargin + $Index * $XStep;

         if ( $DrawVerticalLine ) { $this->drawLine($this->GraphAreaX1+$Data["YMargin"],$Y,$this->GraphAreaX2-$Data["YMargin"],$Y,array("R"=>$VerticalLineR,"G"=>$VerticalLineG,"B"=>$VerticalLineB,"Alpha"=>$VerticalLineAlpha,"Ticks"=>$VerticalLineTicks)); }

         $MinX = $this->GraphAreaX2;
         foreach ($SeriesName as $Key => $SerieName)
          {
           if ( isset($Data["Series"][$SerieName]["Data"][$Index]) )
            {
             $AxisID      = $Data["Series"][$SerieName]["Axis"];

             if ( $OverrideTitle != NULL)
              $Description = $OverrideTitle;
             elseif ( count($SeriesName) == 1 )
              {
               if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
                $Description = $Data["Series"][$SerieName]["Description"]." - ".$Data["Series"][$Data["Abscissa"]]["Data"][$Index];
               else
                $Description = $Data["Series"][$SerieName]["Description"];
              }
             elseif ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
              $Description = $Data["Series"][$Data["Abscissa"]]["Data"][$Index];

             $AxisMode     = $Data["Axis"][$AxisID]["Display"];
             $AxisFormat   = $Data["Axis"][$AxisID]["Format"];
             $AxisUnit     = $Data["Axis"][$AxisID]["Unit"];

             $Serie = "";
             if ( isset($Data["Extended"]["Palette"][$Index] ) )
              {
               $Serie["R"] = $Data["Extended"]["Palette"][$Index]["R"];
               $Serie["G"] = $Data["Extended"]["Palette"][$Index]["G"];
               $Serie["B"] = $Data["Extended"]["Palette"][$Index]["B"];
               $Serie["Alpha"] = $Data["Extended"]["Palette"][$Index]["Alpha"];
              }
             else
              {
               $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
               $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
               $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
               $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];
              }

             if ( count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"]) )
              $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
             else
              $SerieOffset = 0;

             $Value = $Data["Series"][$SerieName]["Data"][$Index];
             if ( $ForceLabels != NULL )
              $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
             else
              $Caption = $this->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);

             $X = floor($this->scaleComputeY($Value,array("AxisID"=>$AxisID)));
             $Y = floor($this->GraphAreaY1 + $XMargin + $Index * $XStep + $SerieOffset);

             if ($X < $MinX) { $MinX = $X; }

             if ( $DrawPoint == LABEL_POINT_CIRCLE )
              $this->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
             elseif ( $DrawPoint == LABEL_POINT_BOX )
              $this->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));

             $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
            }
          }
         $this->drawLabelBox($MinX,$Y-3,$Description,$Series,$Format);

        }
      }
    }

   /* Draw a label box */
   function drawLabelBox($X,$Y,$Title,$Captions,$Format="")
    {
     $NoTitle		= isset($Format["NoTitle"]) ? $Format["NoTitle"] : NULL;
     $BoxWidth		= isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 50;
     $DrawSerieColor	= isset($Format["DrawSerieColor"]) ? $Format["DrawSerieColor"] : TRUE;
     $SerieR		= isset($Format["SerieR"]) ? $Format["SerieR"] : NULL;
     $SerieG		= isset($Format["SerieG"]) ? $Format["SerieG"] : NULL;
     $SerieB		= isset($Format["SerieB"]) ? $Format["SerieB"] : NULL;
     $SerieAlpha	= isset($Format["SerieAlpha"]) ? $Format["SerieAlpha"] : NULL;
     $SerieBoxSize	= isset($Format["SerieBoxSize"]) ? $Format["SerieBoxSize"] : 6;
     $SerieBoxSpacing	= isset($Format["SerieBoxSpacing"]) ? $Format["SerieBoxSpacing"] : 4;
     $VerticalMargin	= isset($Format["VerticalMargin"]) ? $Format["VerticalMargin"] : 10;
     $HorizontalMargin	= isset($Format["HorizontalMargin"]) ? $Format["HorizontalMargin"] : 8;
     $R			= isset($Format["R"]) ? $Format["R"] : $this->FontColorR;
     $G			= isset($Format["G"]) ? $Format["G"] : $this->FontColorG;
     $B			= isset($Format["B"]) ? $Format["B"] : $this->FontColorB;
     $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : $this->FontColorA;
     $FontName		= isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
     $FontSize		= isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
     $TitleMode		= isset($Format["TitleMode"]) ? $Format["TitleMode"] : LABEL_TITLE_NOBACKGROUND;
     $TitleR		= isset($Format["TitleR"]) ? $Format["TitleR"] : $R;
     $TitleG		= isset($Format["TitleG"]) ? $Format["TitleG"] : $G;
     $TitleB		= isset($Format["TitleB"]) ? $Format["TitleB"] : $B;
     $TitleBackgroundR	= isset($Format["TitleBackgroundR"]) ? $Format["TitleBackgroundR"] : 0;
     $TitleBackgroundG	= isset($Format["TitleBackgroundG"]) ? $Format["TitleBackgroundG"] : 0;
     $TitleBackgroundB	= isset($Format["TitleBackgroundB"]) ? $Format["TitleBackgroundB"] : 0;
     $GradientStartR	= isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
     $GradientStartG	= isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
     $GradientStartB	= isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
     $GradientEndR	= isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 220;
     $GradientEndG	= isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 220;
     $GradientEndB	= isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 220;

     if ( !$DrawSerieColor ) { $SerieBoxSize = 0; $SerieBoxSpacing = 0; }

     $TxtPos      = $this->getTextBox($X,$Y,$FontName,$FontSize,0,$Title);
     $TitleWidth  = ($TxtPos[1]["X"] - $TxtPos[0]["X"])+$VerticalMargin*2;
     $TitleHeight = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]);

     if ( $NoTitle ) { $TitleWidth = 0; $TitleHeight = 0; }

     $CaptionWidth = 0; $CaptionHeight = -$HorizontalMargin;
     foreach($Captions as $Key =>$Caption)
      {
       $TxtPos        = $this->getTextBox($X,$Y,$FontName,$FontSize,0,$Caption["Caption"]);
       $CaptionWidth  = max($CaptionWidth,($TxtPos[1]["X"] - $TxtPos[0]["X"])+$VerticalMargin*2);
       $CaptionHeight = $CaptionHeight + max(($TxtPos[0]["Y"] - $TxtPos[2]["Y"]),($SerieBoxSize+2)) + $HorizontalMargin;
      }

     if ( $CaptionHeight <= 5 ) { $CaptionHeight = $CaptionHeight + $HorizontalMargin/2; }

     if ( $DrawSerieColor ) { $CaptionWidth = $CaptionWidth + $SerieBoxSize + $SerieBoxSpacing; }

     $BoxWidth = max($BoxWidth,$TitleWidth,$CaptionWidth);

     $XMin = $X - 5 - floor(($BoxWidth-10) / 2);
     $XMax = $X + 5 + floor(($BoxWidth-10) / 2);

     $RestoreShadow = $this->Shadow;
     if ( $this->Shadow == TRUE )
      {
       $this->Shadow = FALSE;

       $Poly = "";
       $Poly[] = $X+$this->ShadowX; $Poly[] = $Y+$this->ShadowX;
       $Poly[] = $X+5+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
       $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;

       if ( $NoTitle )
        {
         $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2+$this->ShadowX;
         $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2+$this->ShadowX;
        }
       else
        {
         $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3+$this->ShadowX;
         $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3+$this->ShadowX;
        }

       $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
       $Poly[] = $X-5+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
       $this->drawPolygon($Poly,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
      }

     /* Draw the background */
     $GradientSettings = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB);
     if ( $NoTitle )
      $this->drawGradientArea($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-6,DIRECTION_VERTICAL,$GradientSettings);
     else
      $this->drawGradientArea($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-6,DIRECTION_VERTICAL,$GradientSettings);
     $Poly = ""; $Poly[] = $X; $Poly[] = $Y; $Poly[] = $X-5; $Poly[] = $Y-5; $Poly[] = $X+5; $Poly[] = $Y-5;
     $this->drawPolygon($Poly,array("R"=>$GradientEndR,"G"=>$GradientEndG,"B"=>$GradientEndB,"NoBorder"=>TRUE));

     /* Outer border */
     $OuterBorderColor = $this->allocateColor($this->Picture,100,100,100,100);
     imageline($this->Picture,$XMin,$Y-5,$X-5,$Y-5,$OuterBorderColor);
     imageline($this->Picture,$X,$Y,$X-5,$Y-5,$OuterBorderColor);
     imageline($this->Picture,$X,$Y,$X+5,$Y-5,$OuterBorderColor);
     imageline($this->Picture,$X+5,$Y-5,$XMax,$Y-5,$OuterBorderColor);
     if ( $NoTitle )
      {
       imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMin,$Y-5,$OuterBorderColor);
       imageline($this->Picture,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-5,$OuterBorderColor);
       imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$OuterBorderColor);
      }
     else
      {
       imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMin,$Y-5,$OuterBorderColor);
       imageline($this->Picture,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5,$OuterBorderColor);
       imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$OuterBorderColor);
      }

     /* Inner border */
     $InnerBorderColor = $this->allocateColor($this->Picture,255,255,255,100);
     imageline($this->Picture,$XMin+1,$Y-6,$X-5,$Y-6,$InnerBorderColor);
     imageline($this->Picture,$X,$Y-1,$X-5,$Y-6,$InnerBorderColor);
     imageline($this->Picture,$X,$Y-1,$X+5,$Y-6,$InnerBorderColor);
     imageline($this->Picture,$X+5,$Y-6,$XMax-1,$Y-6,$InnerBorderColor);
     if ( $NoTitle )
      {
       imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMin+1,$Y-6,$InnerBorderColor);
       imageline($this->Picture,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax-1,$Y-6,$InnerBorderColor);
       imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$InnerBorderColor);
      }
     else
      {
       imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMin+1,$Y-6,$InnerBorderColor);
       imageline($this->Picture,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax-1,$Y-6,$InnerBorderColor);
       imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$InnerBorderColor);
      }

     /* Draw the separator line */
     if ( $TitleMode == LABEL_TITLE_NOBACKGROUND && !$NoTitle )
      {
       $YPos    = $Y-7-$CaptionHeight-$HorizontalMargin-$HorizontalMargin/2;
       $XMargin = $VerticalMargin / 2;
       $this->drawLine($XMin+$XMargin,$YPos+1,$XMax-$XMargin,$YPos+1,array("R"=>$GradientEndR,"G"=>$GradientEndG,"B"=>$GradientEndB));
       $this->drawLine($XMin+$XMargin,$YPos,$XMax-$XMargin,$YPos,array("R"=>$GradientStartR,"G"=>$GradientStartG,"B"=>$GradientStartB));
      }
     elseif ( $TitleMode == LABEL_TITLE_BACKGROUND )
      {
       $this->drawFilledRectangle($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2,array("R"=>$TitleBackgroundR,"G"=>$TitleBackgroundG,"B"=>$TitleBackgroundB));
       imageline($this->Picture,$XMin+1,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2+1,$XMax-1,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2+1,$InnerBorderColor);
      }

     /* Write the description */
     if ( !$NoTitle )
      $this->drawText($XMin+$VerticalMargin,$Y-7-$CaptionHeight-$HorizontalMargin*2,$Title,array("Align"=>TEXT_ALIGN_BOTTOMLEFT,"R"=>$TitleR,"G"=>$TitleG,"B"=>$TitleB));

     /* Write the value */
     $YPos = $Y-5-$HorizontalMargin; $XPos = $XMin+$VerticalMargin+$SerieBoxSize+$SerieBoxSpacing;
     foreach($Captions as $Key => $Caption)
      {
       $CaptionTxt    = $Caption["Caption"];
       $TxtPos        = $this->getTextBox($XPos,$YPos,$FontName,$FontSize,0,$CaptionTxt);
       $CaptionHeight = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]);

       /* Write the serie color if needed */
       if ( $DrawSerieColor )
        {
         $BoxSettings = array("R"=>$Caption["Format"]["R"],"G"=>$Caption["Format"]["G"],"B"=>$Caption["Format"]["B"],"Alpha"=>$Caption["Format"]["Alpha"],"BorderR"=>0,"BorderG"=>0,"BorderB"=>0);
         $this->drawFilledRectangle($XMin+$VerticalMargin,$YPos-$SerieBoxSize,$XMin+$VerticalMargin+$SerieBoxSize,$YPos,$BoxSettings);
        }

       $this->drawText($XPos,$YPos,$CaptionTxt,array("Align"=>TEXT_ALIGN_BOTTOMLEFT));

       $YPos = $YPos - $CaptionHeight - $HorizontalMargin;
      }

     $this->Shadow = $RestoreShadow;
    }

   /* Draw a basic shape */
   function drawShape($X,$Y,$Shape,$PlotSize,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha)
    {
     if ( $Shape == SERIE_SHAPE_FILLEDCIRCLE )
      {
       if ( $PlotBorder ) { $this->drawFilledCircle($X,$Y,$PlotSize+$BorderSize,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
       $this->drawFilledCircle($X,$Y,$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
      }
     elseif ( $Shape == SERIE_SHAPE_FILLEDSQUARE )
      {
       if ( $PlotBorder ) { $this->drawFilledRectangle($X-$PlotSize-$BorderSize,$Y-$PlotSize-$BorderSize,$X+$PlotSize+$BorderSize,$Y+$PlotSize+$BorderSize,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
       $this->drawFilledRectangle($X-$PlotSize,$Y-$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
      }
     elseif ( $Shape == SERIE_SHAPE_FILLEDTRIANGLE )
      {
       if ( $PlotBorder )
        {
         $Pos = ""; $Pos[]=$X; $Pos[]=$Y-$PlotSize-$BorderSize; $Pos[]=$X-$PlotSize-$BorderSize; $Pos[]=$Y+$PlotSize+$BorderSize; $Pos[]=$X+$PlotSize+$BorderSize; $Pos[]=$Y+$PlotSize+$BorderSize;
         $this->drawPolygon($Pos,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha));
        }

       $Pos = ""; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X-$PlotSize; $Pos[]=$Y+$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y+$PlotSize;
       $this->drawPolygon($Pos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
      }
     elseif ( $Shape == SERIE_SHAPE_TRIANGLE )
      {
       $this->drawLine($X,$Y-$PlotSize,$X-$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
       $this->drawLine($X-$PlotSize,$Y+$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
       $this->drawLine($X+$PlotSize,$Y+$PlotSize,$X,$Y-$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
      }
     elseif ( $Shape == SERIE_SHAPE_SQUARE )
      $this->drawRectangle($X-$PlotSize,$Y-$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
     elseif ( $Shape == SERIE_SHAPE_CIRCLE )
      $this->drawCircle($X,$Y,$PlotSize,$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
     elseif ( $Shape == SERIE_SHAPE_DIAMOND )
      {
       $Pos = ""; $Pos[]=$X-$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y+$PlotSize;
       $this->drawPolygon($Pos,array("NoFill"=>TRUE,"BorderR"=>$R,"BorderG"=>$G,"BorderB"=>$B,"BorderAlpha"=>$Alpha));
      }      
     elseif ( $Shape == SERIE_SHAPE_FILLEDDIAMOND )
      {
       if ( $PlotBorder )
        {
         $Pos = ""; $Pos[]=$X-$PlotSize-$BorderSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y-$PlotSize-$BorderSize; $Pos[]=$X+$PlotSize+$BorderSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y+$PlotSize+$BorderSize;
         $this->drawPolygon($Pos,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha));
        }

       $Pos = ""; $Pos[]=$X-$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y+$PlotSize;
       $this->drawPolygon($Pos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
      }      
    }

   function drawPolygonChart($Points,$Format="")
    {
     $R			= isset($Format["R"]) ? $Format["R"] : 0;
     $G			= isset($Format["G"]) ? $Format["G"] : 0;
     $B			= isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $NoFill		= isset($Format["NoFill"]) ? $Format["NoFill"] : FALSE;
     $NoBorder		= isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
     $BorderR		= isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
     $BorderG		= isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
     $BorderB		= isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
     $BorderAlpha 	= isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha / 2;
     $Surrounding	= isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
     $Threshold         = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;

     if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }

     $RestoreShadow = $this->Shadow;
     $this->Shadow = FALSE;

     $AllIntegers = TRUE;
     for($i=0;$i<=count($Points)-2;$i=$i+2)
      { if ( $this->getFirstDecimal($Points[$i+1]) != 0 ) { $AllIntegers = FALSE; } }

     /* Convert polygon to segments */
     $Segments = "";
     for($i=2;$i<=count($Points)-2;$i=$i+2)
      { $Segments[] = array("X1"=>$Points[$i-2],"Y1"=>$Points[$i-1],"X2"=>$Points[$i],"Y2"=>$Points[$i+1]); }
     $Segments[] = array("X1"=>$Points[$i-2],"Y1"=>$Points[$i-1],"X2"=>$Points[0],"Y2"=>$Points[1]);

     /* Simplify straight lines */
     $Result = ""; $inHorizon = FALSE; $LastX = VOID;
     foreach($Segments as $Key => $Pos)
      {
       if ( $Pos["Y1"] != $Pos["Y2"] )
        {
         if ( $inHorizon ) { $inHorizon = FALSE; $Result[] = array("X1"=>$LastX,"Y1"=>$Pos["Y1"],"X2"=>$Pos["X1"],"Y2"=>$Pos["Y1"]); }

         $Result[] = array("X1"=>$Pos["X1"],"Y1"=>$Pos["Y1"],"X2"=>$Pos["X2"],"Y2"=>$Pos["Y2"]);
        }
       else { if ( !$inHorizon ) { $inHorizon = TRUE; $LastX = $Pos["X1"];} }
      }
     $Segments = $Result;

     /* Do we have something to draw */
     if ( $Segments == "" ) { return(0); }

     /* For segments debugging purpose */
     //foreach($Segments as $Key => $Pos)
     // echo $Pos["X1"].",".$Pos["Y1"].",".$Pos["X2"].",".$Pos["Y2"]."\r\n";

     /* Find out the min & max Y boundaries */
     $MinY = OUT_OF_SIGHT; $MaxY = OUT_OF_SIGHT;
     foreach($Segments as $Key => $Coords)
      {
       if ( $MinY == OUT_OF_SIGHT || $MinY > min($Coords["Y1"],$Coords["Y2"]) ) { $MinY = min($Coords["Y1"],$Coords["Y2"]); }
       if ( $MaxY == OUT_OF_SIGHT || $MaxY < max($Coords["Y1"],$Coords["Y2"]) ) { $MaxY = max($Coords["Y1"],$Coords["Y2"]); }
      }

     if ( $AllIntegers ) { $YStep = 1; } else { $YStep = .5; }

     $MinY = floor($MinY); $MaxY = floor($MaxY);

     /* Scan each Y lines */
     $DefaultColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
     $DebugLine = 0; $DebugColor = $this->allocateColor($this->Picture,255,0,0,100);

     $MinY = floor($MinY); $MaxY = floor($MaxY); $YStep = 1; 

     if ( !$NoFill )
      {
       //if ( $DebugLine ) { $MinY = $DebugLine; $MaxY = $DebugLine; }
       for($Y=$MinY;$Y<=$MaxY;$Y=$Y+$YStep)
        {
         $Intersections = ""; $LastSlope = NULL; $RestoreLast = "-";
         foreach($Segments as $Key => $Coords)
          {
           $X1 = $Coords["X1"]; $X2 = $Coords["X2"]; $Y1 = $Coords["Y1"]; $Y2 = $Coords["Y2"];

           if ( min($Y1,$Y2) <= $Y && max($Y1,$Y2) >= $Y )
            {
             if ( $Y1 == $Y2 )
              { $X = $X1; }
             else
              { $X = $X1 + ( ($Y-$Y1)*$X2 - ($Y-$Y1)*$X1 ) / ($Y2-$Y1); }

             $X = floor($X);

             if ( $X2 == $X1 )
              { $Slope = "!"; }
             else
              {
               $SlopeC = ($Y2 - $Y1) / ($X2 - $X1);
               if( $SlopeC == 0 )
                { $Slope = "="; }
               elseif( $SlopeC > 0 )
                { $Slope = "+"; }
               elseif ( $SlopeC < 0 )
                { $Slope = "-"; }
              }

             if ( !is_array($Intersections) )
              { $Intersections[] = $X; }
             elseif( !in_array($X,$Intersections) )
              { $Intersections[] = $X; }
             elseif( in_array($X,$Intersections) )
              {
               if ($Y == $DebugLine) { echo $Slope."/".$LastSlope."(".$X.") "; }

               if ( $Slope == "=" && $LastSlope == "-"  )                             { $Intersections[] = $X; }
               if ( $Slope != $LastSlope && $LastSlope != "!" && $LastSlope != "=" )  { $Intersections[] = $X; }
               if ( $Slope != $LastSlope && $LastSlope == "!" && $Slope == "+" )      { $Intersections[] = $X; }
              }

             if ( is_array($Intersections) && in_array($X,$Intersections) && $LastSlope == "=" && ($Slope == "-" )) { $Intersections[] = $X; }

             $LastSlope = $Slope;
            }
          }
         if ( $RestoreLast != "-" ) { $Intersections[] = $RestoreLast; echo "@".$Y."\r\n"; }

         if ( is_array($Intersections) )
          {
           sort($Intersections);

           if ($Y == $DebugLine) { print_r($Intersections); }

           /* Remove NULL plots */
           $Result = "";
           for($i=0;$i<=count($Intersections)-1;$i=$i+2)
            {
             if ( isset($Intersections[$i+1]) )
              { if ( $Intersections[$i] != $Intersections[$i+1] ) { $Result[] = $Intersections[$i]; $Result[] = $Intersections[$i+1]; } }
            }

           if ( is_array($Result) )
            {
             $Intersections = $Result;

             $LastX = OUT_OF_SIGHT;
             foreach($Intersections as $Key => $X)
              {
               if ( $LastX == OUT_OF_SIGHT )
                $LastX = $X;
               elseif ( $LastX != OUT_OF_SIGHT )
                {
                 if ( $this->getFirstDecimal($LastX) > 1 ) { $LastX++; }

                 $Color = $DefaultColor;
                 if ( $Threshold != NULL )
                  {
                   foreach($Threshold as $Key => $Parameters)
                    {
                     if ( $Y <= $Parameters["MinX"] && $Y >= $Parameters["MaxX"])
                      {
                       if ( isset($Parameters["R"]) ) { $R = $Parameters["R"]; } else { $R = 0; }
                       if ( isset($Parameters["G"]) ) { $G = $Parameters["G"]; } else { $G = 0; }
                       if ( isset($Parameters["B"]) ) { $B = $Parameters["B"]; } else { $B = 0; }
                       if ( isset($Parameters["Alpha"]) ) { $Alpha = $Parameters["Alpha"]; } else { $Alpha = 100; }
                       $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
                      }
                    }
                  }

                 imageline($this->Picture,$LastX,$Y,$X,$Y,$Color);

                 if ( $Y == $DebugLine) { imageline($this->Picture,$LastX,$Y,$X,$Y,$DebugColor); }

                 $LastX = OUT_OF_SIGHT;
                }
              }
            }
          }
        }
      }

     /* Draw the polygon border, if required */
     if ( !$NoBorder)
      {
       foreach($Segments as $Key => $Coords)
        $this->drawLine($Coords["X1"],$Coords["Y1"],$Coords["X2"],$Coords["Y2"],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Threshold"=>$Threshold));
      }

     $this->Shadow = $RestoreShadow;
    }
  }
?>