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
|
/* -*- Mode: C++ -*-
KDChart - a multi-platform charting engine
*/
/****************************************************************************
** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB. All rights reserved.
**
** This file is part of the KDChart library.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid commercial KDChart licenses may use this file in
** accordance with the KDChart Commercial License Agreement provided with
** the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.klaralvdalens-datakonsult.se/?page=products for
** information about KDChart Commercial License Agreements.
**
** Contact [email protected] if any conditions of this
** licensing are not clear to you.
**
**********************************************************************/
#include "KDChartBarPainter.h"
#include <KDChartParams.h>
#include <tqpainter.h>
#include <stdlib.h>
/**
\class KDChartBarPainter KDChartBarPainter.h
\brief A chart painter implementation that can paint bar charts.
*/
/**
Constructor. Sets up internal data structures as necessary.
\param params the KDChartParams structure that defines the chart
*/
KDChartBarPainter::KDChartBarPainter( KDChartParams* params ) :
KDChartAxesPainter( params )
{
// This constructor intentionally left blank so far; we cannot setup the
// tqgeometry yet since we do not know the size of the painter.
}
/**
Destructor.
*/
KDChartBarPainter::~KDChartBarPainter()
{
// intentionally left blank
}
bool KDChartBarPainter::isNormalMode() const
{
return KDChartParams::BarNormal == params()->barChartSubType();
}
int KDChartBarPainter::clipShiftUp( bool normalMode, double areaWidthP1000 ) const
{
const bool bThreeDBars = params()->threeDBars() || (KDChartParams::BarMultiRows == params()->barChartSubType());
return ( normalMode && !bThreeDBars )
? static_cast < int > ( areaWidthP1000 * 16.0 )
: 0;
}
void KDChartBarPainter::initMyPainter( TQPainter* painter )
{
_myPainter = painter;
_painterDX = 0.0;
_painterDY = 0.0;
}
void KDChartBarPainter::shiftMyPainter( double dx, double dy )
{
if( dx != 0.0 || dy != 0.0 ){
_myPainter->translate(dx, dy);
_painterDX += dx;
_painterDY += dy;
}
}
void KDChartBarPainter::shiftMyPainterBack()
{
if( _painterDX != 0.0 || _painterDY != 0.0 ){
_myPainter->translate(-_painterDX, -_painterDY);
_painterDX = 0.0;
_painterDY = 0.0;
}
}
void KDChartBarPainter::calculateXFront1_2( bool bNormalMode, bool bIsVeryFirstBar, bool bIsFirstDataset, bool _bThreeDBars,
double xpos, double valueBlockGap, double datasetGap, double frontBarWidth,
int& frontX1, int& frontX2, int& prevFrontX2 ){
if( _bThreeDBars || bIsVeryFirstBar || !bNormalMode )
frontX1 = static_cast<int>( xpos );
else if( bIsFirstDataset )
frontX1 = prevFrontX2 + static_cast <int> ( valueBlockGap ) + 1;
else
frontX1 = prevFrontX2 + static_cast < int > ( datasetGap ) + 1;
// Note: frontX2 is calculated by using xpos but NOT by using frontX1.
// So we make sure that (a) the gaps between all bars of one dataset
// are exactly the same size, and that (b) the bars are automatically
// adjusted in their width: to match their very position within the abscissa range.
// Adjusting will result in them being ONE pixel wider sometimes.
frontX2 = static_cast < int > ( xpos + frontBarWidth );
prevFrontX2 = frontX2;
}
TQPointArray rectToPointArray( const TQRect& r )
{
TQPointArray a(4);
a.putPoints( 0, 4, r.left(),r.top(), r.right(),r.top(), r.right(),r.bottom(), r.left(),r.bottom() );
return a;
}
void KDChartBarPainter::specificPaintData( TQPainter* painter,
const TQRect& ourClipRect,
KDChartTableDataBase* data,
KDChartDataRegionList* regions,
const KDChartAxisParams* ordinatePara,
bool bNormalMode,
uint chart,
double logWidth,
double areaWidthP1000,
double logHeight,
double axisYOffset,
double minColumnValue,
double maxColumnValue,
double columnValueDistance,
uint chartDatasetStart,
uint chartDatasetEnd,
uint datasetStart,
uint datasetEnd )
{
/****************Pending Michel***********************
*Rectangles are painted in the following order: *
*front , right side, top. *
*Store the painted rectangles in order to paint *
*them in relation to each other for more precision. *
****************************************************/
TQRect frontRectPositive,frontRectNegative,
rightRectPositive, rightRectNegative,
excessRectPositive,excessRectNegative;
_areaP1000 = areaWidthP1000;
if( !data ) return;
// qDebug("datasetStart: %i datasetEnd: %i", datasetStart, datasetEnd);
const TQPen defaultOutlinePen( params()->outlineDataColor(),
params()->outlineDataLineWidth(),
params()->outlineDataLineStyle() );
abscissaInfos ai;
ai.bCenterThePoints = true;
calculateAbscissaInfos( *params(), *data,
datasetStart, datasetEnd,
logWidth, _dataRect,
ai );
const TQRect devRect( painter->window() );
initMyPainter( painter );
const bool ordinateIsLogarithmic
= KDChartAxisParams::AxisCalcLogarithmic == ordinatePara->axisCalcMode();
const bool bMultiRows = KDChartParams::BarMultiRows == params()->barChartSubType();
_bThreeDBars = params()->threeDBars() || bMultiRows;
int numChartDataEntryDatasets = 0;
uint myLastDataEntryDataset = 0;
for( uint iD = chartDatasetStart; iD <= chartDatasetEnd; ++iD ){
if( params()->chartSourceMode( iD ) == KDChartParams::DataEntry ){
++numChartDataEntryDatasets;
myLastDataEntryDataset = iD;
}
}
const bool bHadClipping = painter->hasClipping();
//this allow the height/size of the bar to be painted fully
if( bMultiRows ) {
painter->setClipping( false );
}
// Number of columns in one dataset: If -1, use all values,
// otherwise use the specified number of values.
int numValues = 0;
if ( params()->numValues() != -1 )
numValues = params()->numValues();
else
numValues = data->usedCols();
double datasetGap = bMultiRows
? 0.0
: params()->datasetGap()
* ( params()->datasetGapIsRelative()
? areaWidthP1000
: 1.0 );
double valueBlockGap = bMultiRows
? 0.0
: params()->valueBlockGap()
* ( params()->valueBlockGapIsRelative()
? areaWidthP1000
: 1.0 );
// This is the same for all three bar types except for multi-bar Surface charts.
double spaceBetweenValueBlocks = bMultiRows
? 0.0
: static_cast<int>( valueBlockGap ) * numValues;
// Set some tqgeometry values that apply to bar charts only
double totalNumberOfBars = 0.0;
double spaceBetweenDatasets = 0.0;
switch ( params()->barChartSubType() ) {
case KDChartParams::BarNormal: {
totalNumberOfBars = numChartDataEntryDatasets * numValues;
spaceBetweenDatasets = datasetGap
* ( totalNumberOfBars - numValues );
break;
}
case KDChartParams::BarStacked:
case KDChartParams::BarPercent:
case KDChartParams::BarMultiRows:
totalNumberOfBars = numValues;
spaceBetweenDatasets = 0; // always 0 when stacked/percent/multi-rows
break;
default:
qFatal( "Unsupported bar chart type" );
};
double barWidth = 0.0;
if( params()->barWidth() == KDCHART_AUTO_SIZE ) {
//Default auto calc. to optimize when many bars datasetGap == blockGap/2 == barWidth/2
//unless valueBlockGap or datasetGap are different from default values == users value
barWidth = logWidth / totalNumberOfBars;
do {
barWidth -= 0.1;
params()->valueBlockGap() != 24 ? spaceBetweenValueBlocks = params()->valueBlockGap() * numValues
: spaceBetweenValueBlocks = ( barWidth/2 ) * numValues;
if ( spaceBetweenDatasets != 0 )
params()->datasetGap()!= 6 ? spaceBetweenDatasets = params()->datasetGap() * ( totalNumberOfBars - numValues )
: spaceBetweenDatasets = ( barWidth/4 ) * ( totalNumberOfBars - numValues );
}
while ( barWidth*totalNumberOfBars + spaceBetweenValueBlocks + spaceBetweenDatasets > logWidth );
valueBlockGap = ( spaceBetweenValueBlocks )/ numValues;
if ( spaceBetweenDatasets != 0 )
datasetGap = spaceBetweenDatasets / ( totalNumberOfBars - numValues );
barWidth = (logWidth - ( valueBlockGap * numValues ) - ( datasetGap * ( totalNumberOfBars - numValues ) ) ) / totalNumberOfBars;
;
/* Debug space available
qDebug ( " logWidth %f" , logWidth );
qDebug ( "compare value %f", barWidth*totalNumberOfBars + spaceBetweenValueBlocks + datasetGap * ( totalNumberOfBars - numValues ) );
*/
} else if( 0 > params()->barWidth() )
barWidth = params()->barWidth() * -areaWidthP1000;
else
barWidth = params()->barWidth();
//sideBarWidth: pre-calculate in order to have a reference
//we will correct according to the available space later.
//This in order to center the labels in relation to the front width
//when painting 3DBars
double sideBarWidth = _bThreeDBars
? ( barWidth - barWidth / (1.0 + params()->cosThreeDBarAngle()) ) *
params()->threeDBarDepth()
: 0.0;
const double frontBarWidth = _bThreeDBars && !bMultiRows
? barWidth - sideBarWidth
: barWidth;
//correct the width for the side of the bar
double totalThreeDBarWidth = totalNumberOfBars*barWidth + sideBarWidth;
double totalSpaceOccupied = totalThreeDBarWidth + spaceBetweenDatasets + spaceBetweenValueBlocks;
if ( logWidth < totalSpaceOccupied) {
sideBarWidth -= (totalSpaceOccupied /*+ spaceBetweenDatasets + spaceBetweenValueBlocks*/ - logWidth)/totalNumberOfBars;
//qDebug ( "logWidth %f", logWidth );
//qDebug ( "totalSpaceOccupied %f", totalSpaceOccupied );
}
const double sideBarHeight = sideBarWidth;
double pixelsPerUnit = 0.0;
if ( params()->barChartSubType() != KDChartParams::BarPercent ) // not used for percent
pixelsPerUnit = logHeight / ( columnValueDistance ? columnValueDistance : 10 );
//qDebug("\nordinatePara->trueAxisLow() = %f", ordinatePara->trueAxisLow());
//qDebug( "ordinatePara->trueAxisHigh() = %f", ordinatePara->trueAxisHigh());
//qDebug( "sideBarHeight = %f", sideBarHeight);
//qDebug( "pixelsPerUnit = %f", pixelsPerUnit);
double zeroXAxisI;
if ( params()->barChartSubType() == KDChartParams::BarPercent ) {
if ( minColumnValue == 0.0 )
zeroXAxisI = 0.0;
else if ( maxColumnValue == 0.0 )
zeroXAxisI = logHeight - sideBarHeight;
else
zeroXAxisI = ( logHeight - sideBarHeight ) / 2.0;
} else {
zeroXAxisI = logHeight
- ordinatePara->axisZeroLineStartY()
+ _dataRect.y();
}
double shiftUpperBars = (params()->barChartSubType() != KDChartParams::BarPercent)
&& (ordinatePara->axisTrueLineWidth() % 2)
? 1.0
: 0.0;
// Initializing drawing positions
double yposPositivesStart = logHeight;
double yposNegativesStart = logHeight;
if( params()->barChartSubType() == KDChartParams::BarPercent ){
yposPositivesStart += axisYOffset;
yposNegativesStart += axisYOffset;
}
for ( int iPaintExtraLinesOrTheData = 0;
iPaintExtraLinesOrTheData < 3;
++iPaintExtraLinesOrTheData )
{
const bool bDrawExtraLines = (1 != iPaintExtraLinesOrTheData);
const bool bDrawExtraLinesInFront = (2 == iPaintExtraLinesOrTheData);
double xpos = 0.0;
if ( _bThreeDBars && !bMultiRows )
xpos = 0.0 + (barWidth/2) + (valueBlockGap/2) - (frontBarWidth/2);
else
xpos = 0.0 + (valueBlockGap / 2.0);
double yposPositives = yposPositivesStart;
double yposNegatives = yposNegativesStart;
/* Pending Michel: no need for this anymore */
//double totalThreeDBarWidth = bMultiRows
//? barWidth + sideBarWidth
// : barWidth;
double nShiftX = bMultiRows
? sideBarWidth
: 0.0;
double nShiftY = bMultiRows
? sideBarHeight
: 0.0;
double valueTotal = 0.0; // valueTotal is used for percent bars only
// iterate over all columns: item1, item2, item3 ...
int prevFrontX2 = 0;
bool bIsVeryFirstBar = true;
for ( int value = 0; value < numValues; ++value ) {
bool bFirstValidValueUnknown = true;
uint firstValidValue = 0;
uint lastValidPositiveValue = 0;
double maxValueInThisColumn = 0.0, minValueInThisColumn = 0.0;
if ( params()->barChartSubType() == KDChartParams::BarStacked ||
params()->barChartSubType() == KDChartParams::BarPercent) {
valueTotal = 0.0;
// iterate over datasets of this axis only:
for ( uint dataset = datasetStart;
dataset <= datasetEnd;
++dataset ) {
TQVariant vVal;
if( data->cellCoord( dataset, value, vVal, 1 )
&& params()->chartSourceMode( dataset ) == KDChartParams::DataEntry
&& TQVariant::Double == vVal.type() ){
const double cellValue
= ordinateIsLogarithmic
? log10( vVal.toDouble() )
: vVal.toDouble();
//qDebug("value %u dataset %u logHeight %f", value,dataset,logHeight);
if( bFirstValidValueUnknown ){
firstValidValue = dataset;
bFirstValidValueUnknown = false;
}
if( 0.0 <= cellValue )
lastValidPositiveValue = dataset;
maxValueInThisColumn = TQMAX( maxValueInThisColumn, cellValue );
minValueInThisColumn = TQMIN( minValueInThisColumn, cellValue );
if( params()->barChartSubType() == KDChartParams::BarPercent /*||
params()->barChartSubType() == KDChartParams::BarStacked*/ )
valueTotal += cellValue;
}
}
}
//qDebug("shiftMyPainter( (numChartDataEntryDatasets-1)*nShiftX, (numChartDataEntryDatasets-1)*-nShiftY );");
shiftMyPainter( (numChartDataEntryDatasets-1)*nShiftX, (numChartDataEntryDatasets-1)*-nShiftY );
// iterate over all datasets of this chart:
// (but draw only the bars of this axis)
bool bIsFirstDataset = true;
for ( uint dataset = bMultiRows
? chartDatasetEnd
: chartDatasetStart;
dataset >= chartDatasetStart && dataset <= chartDatasetEnd;
bMultiRows
? --dataset
: ++dataset ) {
//qDebug("value %u dataset %u logHeight %f", value,dataset,logHeight);
const bool bDataEntrySourceMode
= (params()->chartSourceMode( dataset ) == KDChartParams::DataEntry);
TQVariant coord1;
TQVariant coord2;
int propID;
if( data->cellContent( dataset, value, coord1, coord2, propID )
&& TQVariant::Double == coord1.type() ){
const double cellValue
= ordinateIsLogarithmic
? log10( coord1.toDouble() )
: coord1.toDouble();
//qDebug("b");
// there is a numeric value
double barHeight;
if ( params()->barChartSubType() == KDChartParams::BarPercent )
barHeight = ( cellValue / valueTotal ) * fabs(zeroXAxisI - logHeight );
else {
barHeight = pixelsPerUnit * cellValue;
if( 0.0 <= barHeight )
//barHeight = TQMAX(0.0, barHeight - sideBarHeight);
barHeight = barHeight - sideBarHeight;
else
barHeight -= sideBarHeight;
}
// This little adjustment avoids a crash when trying
// to retrieve the bounding rect of a zero size region...
if( 0 == barHeight || 0.0 == barHeight ) {
barHeight = 1.0; // makes sense to have a min size anyway
}
// draw only the bars belonging to the axis
// which we are processing currently
if( dataset >= datasetStart && dataset <= datasetEnd ) {
//qDebug("b2");
// calculate Abscissa axis value, if there are X coordinates
// ---------------------------------------------------------
bool skipMe = false;
if( ai.bCellsHaveSeveralCoordinates ){
skipMe = !calculateAbscissaAxisValue( coord2,
ai, 0, xpos );
// adjust bar position to have it horizontally centered to the point
if( ai.bAbscissaHasTrueAxisDtValues &&
TQVariant::DateTime == coord2.type() )
xpos -= frontBarWidth / 2.0;
}
if( !skipMe ){
// Configure colors
TQColor myBarColor( params()->dataColor( dataset ) );
TQColor myShadow1Color( params()->dataShadow1Color( dataset ) );
TQColor myShadow2Color( params()->dataShadow2Color( dataset ) );
// Get default values for extra lines and their markers
const KDChartParams::LineMarkerStyle
defaultMarkerStyle = params()->lineMarkerStyle( dataset );
const TQPen defaultPen( params()->lineColor().isValid()
? params()->lineColor()
: params()->dataColor( dataset ),
params()->lineWidth(),
params()->lineStyle( dataset ) );
// --------------------------------------------------------
// determine any 'extra' properties assigned to this cell
// by traversing the property set chain (if necessary)
// --------------------------------------------------------
KDChartPropertySet propSet;
bool bCellPropertiesFound =
params()->calculateProperties( propID,
propSet );
bool bShowThisBar = bDataEntrySourceMode;
if( bCellPropertiesFound ){
if( bShowThisBar && !bDrawExtraLines ){
int iDummy;
if( propSet.hasOwnShowBar( iDummy, bShowThisBar ) ){
// NOP
}
if( propSet.hasOwnBarColor( iDummy, myBarColor ) ){
// adjust the shadow colors
params()->calculateShadowColors( myBarColor,
myShadow1Color,
myShadow2Color );
}
}
}
if( !bDrawExtraLines || bCellPropertiesFound ){
//TQRegion* region = 0;
KDChartDataRegion::PointArrayList * pointArrayList = 0;
if( bDataEntrySourceMode && !bDrawExtraLines ){
painter->setPen( defaultOutlinePen );
if ( myBarColor.isValid() )
painter->setBrush( myBarColor );
else
painter->setBrush( NoBrush );
// Prepare region for detection of mouse clicks
// and for finding anchor positions of data value texts
if ( regions )
pointArrayList = new KDChartDataRegion::PointArrayList();
}
// Start drawing
int frontX1 = 0;
int frontX2 = 0;
bool tooLow = false;
bool tooHigh = false;
if ( cellValue < 0 || cellValue < minColumnValue ) {
double maxValueYPos = maxColumnValue * pixelsPerUnit;
double yZero = yposNegatives - zeroXAxisI - sideBarHeight;
tooLow = (barHeight - yZero + logHeight + axisYOffset) < 0;
/*we need to handle those values in case we have a negative view*/
if ( cellValue <= 0 && cellValue > maxColumnValue && minColumnValue < 0 && maxColumnValue < 0 )
tooLow = true;
if ( tooLow && ( bNormalMode || bMultiRows) ) {
double delta = 0.0125 * logHeight;
double height = -1*(-1.0 * (yZero + sideBarHeight) - 2 * delta);
double height1 = height - 3.0 * delta;
int yArrowGap = static_cast < int > ( 2.5 * delta );
calculateXFront1_2( bNormalMode, bIsVeryFirstBar, bIsFirstDataset, _bThreeDBars,
xpos, valueBlockGap, datasetGap, frontBarWidth,
frontX1, frontX2, prevFrontX2 );
const int xm = static_cast < int > ( (frontX1 + frontX2) / 2.0 );
TQRect rect( ourClipRect );
rect.setHeight( static_cast<int>( rect.height() + 3.0 * delta ) );
painter->setClipRect( rect );
//Pending Michel: Make sure the point of the arrow is always at the same distance
//from the X axis reference to the point of the arrow.
int arrowXAxisGap;
TQPoint arrowTop( xm,static_cast<int>( yZero + height1 + 2 * yArrowGap) );
if ( arrowTop.y()== yposNegatives )
arrowXAxisGap = -2;
else
arrowXAxisGap = static_cast <int> (yposNegatives - arrowTop.y() - 2);
if( bDrawExtraLines ){
drawExtraLinesAndMarkers(
propSet,
defaultPen,
defaultMarkerStyle,
xm, static_cast<int>( yZero + height1 ),
painter,
ai.abscissaPara,
ordinatePara,
areaWidthP1000,
logHeight/1000.0,
bDrawExtraLinesInFront );
}else if( bShowThisBar ){
if( params()->drawSolidExcessArrows() ) {
/* PENDING Michel:
* Here we have two situations.
* The value is too low because over the Min negative value
* or it is not within the configured view.
*/
// Draw solid excess arrows negatives
TQPointArray points( 5 );
/*this works in a positive view -> 200 500*/
points.setPoint( 0, frontX1, cellValue < 0 ?
static_cast<int>(yZero+height1 - 3.0*delta)+(2*yArrowGap)+ arrowXAxisGap:
static_cast<int>( yZero + height1)+(2*yArrowGap)+ arrowXAxisGap);
points.setPoint( 1, frontX2, cellValue < 0 ?
static_cast<int>(yZero+height1 - 3.0*delta)+(2*yArrowGap)+ arrowXAxisGap:
static_cast<int>( yZero + height1)+(2*yArrowGap)+ arrowXAxisGap );
points.setPoint( 2, frontX2, cellValue < 0 ?
static_cast<int>(yZero+height1 - 3.0*delta)+(2*yArrowGap)+ arrowXAxisGap:
static_cast<int>( yZero + height1)+(2*yArrowGap)+ arrowXAxisGap);
points.setPoint( 3, xm, cellValue < 0 ?
static_cast<int>( yZero + height1)+(2*yArrowGap)+ arrowXAxisGap:
static_cast<int>(yZero+height1 - 3.0*delta)+(2*yArrowGap)+ arrowXAxisGap);
points.setPoint( 4, frontX1, cellValue < 0 ?
static_cast<int>(yZero+height1 - 3.0*delta)+(2*yArrowGap)+ arrowXAxisGap:
static_cast<int>( yZero + height1)+(2*yArrowGap)+ arrowXAxisGap);
/* 0 between start and end -> -500 500*/
if ( minColumnValue < 0 && maxColumnValue > 0 ) {
points.setPoint(0, points.point(0).x(), static_cast <int> (yposNegatives - zeroXAxisI) );
points.setPoint(1, points.point(1).x(), static_cast <int> (yposNegatives - zeroXAxisI) );
}
/* negative view -> -200 -500 */
if ( minColumnValue < 0 && maxColumnValue < 0 ) {
/*value negative or zero > maxColumnValue*/
if ( cellValue > maxColumnValue ) {
// the view is under Yaxis 0 level
// we need to show a symbol for the bars which are over the Yaxis.
// calculate the coordinate and direction for the arrow.
// arrow downward for negative values and upward for positives value
int diffArrowBase = points.point(2).y() - points.point(3).y();
double maxValueYPos = maxColumnValue * pixelsPerUnit;
double minValueYPos = minColumnValue * pixelsPerUnit;
double adjustedArrow = (cellValue == 0 ? minValueYPos - maxValueYPos + diffArrowBase + 2:
minValueYPos - maxValueYPos - diffArrowBase + 1);
points.setPoint( 0, frontX1, points.point(0).y() + static_cast <int> (adjustedArrow));
points.setPoint( 1, frontX2, points.point(1).y() + static_cast <int> (adjustedArrow ));
points.setPoint( 2, frontX2, points.point(2).y() + static_cast <int> (adjustedArrow));
points.setPoint( 3, xm, points.point(3).y() + static_cast <int> (adjustedArrow));
points.setPoint( 4, frontX1, points.point(4).y() + static_cast <int> (adjustedArrow));
}
/*value < mincolumn value*/
if ( cellValue < minColumnValue ) {
points.setPoint( 0, frontX1, static_cast <int> ( yZero - maxValueYPos ) );
points.setPoint( 1, frontX2, static_cast <int> ( yZero - maxValueYPos ) );
}
}
/*Pending Michel: case setbarWidth */
//adjust the painting in case we have a user given Width allow it
//to be larger than the auto calculated width in case we want to overlap
if ( params()->userWidth() != 0 ) {
int userwidth = 0;
if ( params()->userWidth() < 0 )
userwidth = static_cast <int> (params()->userWidth() * -areaWidthP1000);
else
userwidth = static_cast <int> (params()->userWidth() * areaWidthP1000);
//if ( userwidth < frontBarWidth ) {
TQRect tmpRect ( points.point(0), points.point(2));
points.setPoint(0, static_cast <int>(tmpRect.center().x() - userwidth/2),
points.point(0).y());
points.setPoint(1, static_cast <int>(tmpRect.center().x() + userwidth/2),
points.point(1).y());
points.setPoint(2, static_cast <int>(tmpRect.center().x() + userwidth/2),
points.point(2).y());
points.setPoint(4, static_cast <int>(tmpRect.center().x() - userwidth/2),
points.point(4).y());
//}
}
if ( bMultiRows )painter->setClipping( false );
painter->drawPolygon( points );
//correct the y position: displaying position for the value label
TQPoint tpLeft (points.point(4).x(), points.point(4).y() - 2 * yArrowGap );
TQPoint tpRight(points.point(2).x(), points.point(2).y() - 2 * yArrowGap );
//store the front rectangle
excessRectNegative.setTopLeft(tpLeft);
excessRectNegative.setTopRight(tpRight);
excessRectNegative.setBottomRight(points.point(1));
excessRectNegative.setBottomLeft(points.point(0));
// Don't use points for drawing after this!
if ( pointArrayList ) {
if ( cellValue < 0 ) {
//correction for labels vertical position
int size = static_cast <int> ( ( points.point( 3 ).y() - tpRight.y() + excessRectNegative.width() )/2 );
points.setPoint( 4 ,tpLeft );
points.setPoint( 2, tpRight );
if ( cellValue < maxColumnValue )
points.translate( _dataRect.x(), -_dataRect.y() - size );
else
points.translate( _dataRect.x(), _dataRect.y() );
} else
points.translate( _dataRect.x(), _dataRect.y() );
pointArrayList->append( points );
}
} else {
// Draw split excess arrows negatives
/* PENDING Michel:
* Here we have two situations.
* The value is too low because over the Min negative value
* The value is not within the configured view..
*/
TQPointArray points( 5 );
/*this works in a positive view -> 200 500*/
points.setPoint( 0, frontX1, cellValue < 0 ?
static_cast<int>(yZero+height1 - 3.0*delta) + arrowXAxisGap:
static_cast<int>( yZero + height1)+(2 * yArrowGap)+ arrowXAxisGap);
points.setPoint( 1, frontX2, cellValue < 0 ?
static_cast<int>(yZero+height1 - 3.0*delta) + arrowXAxisGap:
static_cast<int>( yZero + height1)+(2 * yArrowGap)+ arrowXAxisGap);
points.setPoint( 2, frontX2, cellValue < 0 ?
static_cast<int>(yZero+height1 - 3.0*delta) + arrowXAxisGap:
static_cast<int>( yZero + height1)+(2 * yArrowGap)+ arrowXAxisGap);
points.setPoint( 3, xm, cellValue < 0 ?
static_cast<int>( yZero + height1) + arrowXAxisGap:
static_cast<int>(yZero+height1 - 3.0*delta)+(2 * yArrowGap)+ arrowXAxisGap);
points.setPoint( 4, frontX1, cellValue < 0 ?
static_cast<int>(yZero+height1 - 3.0*delta) + arrowXAxisGap:
static_cast<int>( yZero + height1)+(2 * yArrowGap)+ arrowXAxisGap);
/* 0 between start and end -> -500 500*/
if ( minColumnValue < 0 && maxColumnValue > 0 ) {
points.setPoint(0, points.point(0).x(), static_cast <int> (yposNegatives - zeroXAxisI) );
points.setPoint(1, points.point(1).x(), static_cast <int> (yposNegatives - zeroXAxisI) );
}
/* negative view -> -200 -500 */
if ( minColumnValue < 0 && maxColumnValue < 0 ) {
/*value negative or zero > maxColumnValue*/
if ( cellValue > maxColumnValue ) {
// the view is under Yaxis 0 level
// we need to show a symbol for the bars which are over the Yaxis.
// calculate the coordinate and direction for the arrow.
// arrow downward for negative values and upward for positives value
int diffArrowBase = points.point(2).y() - points.point(3).y();
double maxValueYPos = maxColumnValue * pixelsPerUnit;
points.setPoint( 0, frontX1, static_cast <int> ( yZero - maxValueYPos) );
points.setPoint( 1, frontX2, static_cast <int> ( yZero - maxValueYPos) );
points.setPoint( 2, frontX2, static_cast <int> ( yZero - maxValueYPos) );
points.setPoint( 3, xm, static_cast <int> ( yZero - maxValueYPos - diffArrowBase ) );
points.setPoint( 4, frontX1, static_cast <int> ( yZero - maxValueYPos) );
}
/*value < mincolumn value*/
if ( cellValue < minColumnValue ) {
points.setPoint( 0, frontX1, static_cast <int> ( yZero - maxValueYPos) );
points.setPoint( 1, frontX2, static_cast <int> ( yZero - maxValueYPos) );
}
}
//Pending Michel adjust the painting in case we have a user given Width
//allow it to be larger than the auto calculated width in case we want
//to overlap
if ( params()->userWidth() != 0 ) {
int userwidth = 0;
if ( params()->userWidth() < 0 )
userwidth = static_cast <int> (params()->userWidth() * -areaWidthP1000);
else
userwidth = static_cast <int> (params()->userWidth() * areaWidthP1000);
//if ( userwidth < frontBarWidth ) {
TQRect tmpRect ( points.point(0), points.point(2));
points.setPoint(0, static_cast <int>(tmpRect.center().x() - userwidth/2),
points.point(0).y());
points.setPoint(1, static_cast <int>(tmpRect.center().x() + userwidth/2),
points.point(1).y());
points.setPoint(2, static_cast <int>(tmpRect.center().x() + userwidth/2),
points.point(2).y());
points.setPoint(4, static_cast <int>(tmpRect.center().x() - userwidth/2),
points.point(4).y());
}
if ( bMultiRows )painter->setClipping( false );
painter->drawPolygon( points );
//correct the y position: displaying position for the value label
TQPoint tpLeft (points.point(4).x(), points.point(4).y() - 2 * yArrowGap );
TQPoint tpRight(points.point(2).x(), points.point(2).y() - 2 * yArrowGap );
//store the excess front rectangle
excessRectNegative.setTopLeft(tpLeft);
excessRectNegative.setTopRight(tpRight);
excessRectNegative.setBottomRight(points.point(1));
excessRectNegative.setBottomLeft(points.point(0));
// Don't use points for drawing after this!
if ( pointArrayList ) {
if ( cellValue < 0 ) {
//calculate correction for labels vertical position
int size = static_cast <int> ( ( points.point( 3 ).y() - tpRight.y() + excessRectNegative.width() )/2 );
if ( cellValue < maxColumnValue )
points.translate( _dataRect.x(), -_dataRect.y() - size );
else
points.translate( _dataRect.x(), _dataRect.y() + ( 2 * yArrowGap ) );
} else
points.translate( _dataRect.x(), -_dataRect.y() );
pointArrayList->append( points );
}
TQPointArray points2( 6 );
points2.setPoint( 0, frontX1, cellValue < 0 ?
static_cast<int>( yZero + height1 - 3.0 * delta ) + arrowXAxisGap:
static_cast<int>(yZero + height1) + arrowXAxisGap);
points2.setPoint( 1, xm, cellValue < 0 ?
static_cast<int>(yZero + height1) + arrowXAxisGap:
static_cast<int>( yZero + height1 - 3.0 * delta ) + arrowXAxisGap);
points2.setPoint( 2, frontX2, cellValue < 0 ?
static_cast<int>(yZero + height1 - 3.0 * delta) + arrowXAxisGap:
static_cast<int>(yZero + height1) + arrowXAxisGap);
points2.setPoint( 3, frontX2, cellValue < 0 ?
static_cast<int>(yZero + height1 - 3.75 * delta) + arrowXAxisGap :
static_cast<int>(yZero + height1 - 0.75 * delta) + arrowXAxisGap);
points2.setPoint( 4, xm, cellValue < 0 ?
static_cast<int>(yZero + height1 - 0.75 * delta) + arrowXAxisGap:
static_cast<int>(yZero + height1 - 3.75 * delta) + arrowXAxisGap);
points2.setPoint( 5, frontX1, cellValue < 0 ?
static_cast<int>(yZero + height1 - 3.75 * delta) + arrowXAxisGap:
static_cast<int>(yZero + height1 - 0.75 * delta) + arrowXAxisGap);
points2.translate( 0, yArrowGap );
if ( minColumnValue < 0 && maxColumnValue < 0 && cellValue > maxColumnValue ) {
// the view is under Yaxis 0 level
// we need to show a symbol for the bars which are over the Yaxis.
// calculate the coordinate and direction for the arrow.
// arrow downward for negative values and upward for positives value
int diffArrowBase = points.point(2).y() - points.point(3).y();
double maxValueYPos = maxColumnValue * pixelsPerUnit;
double minValueYPos = minColumnValue * pixelsPerUnit;
double adjustedArrow = cellValue == 0 ? minValueYPos - maxValueYPos + diffArrowBase:
minValueYPos - maxValueYPos - diffArrowBase + 1;
points2.setPoint( 0, frontX1, points2.point(0).y()
+ static_cast <int> (adjustedArrow - diffArrowBase + yArrowGap) );
points2.setPoint( 1, xm, points2.point(1).y()
+ static_cast <int> (adjustedArrow - diffArrowBase + yArrowGap) );
points2.setPoint( 2, frontX2, points2.point(2).y()
+ static_cast <int> (adjustedArrow - diffArrowBase + yArrowGap) );
points2.setPoint( 3, frontX2, points2.point(3).y()
+ static_cast <int> (adjustedArrow - diffArrowBase + yArrowGap) );
points2.setPoint( 4, xm, points2.point(4).y()
+ static_cast <int> (adjustedArrow - diffArrowBase + yArrowGap) );
points2.setPoint( 5, frontX1, points2.point(5).y()
+ static_cast <int> (adjustedArrow - diffArrowBase + yArrowGap) );
}
//Pending Michel adjust the painting in case we have a user given Width
//allow it to be larger than the auto calculated width in case we want
//to overlap
if ( params()->userWidth() != 0 ) {
int userwidth = 0;
if ( params()->userWidth() < 0 )
userwidth = static_cast <int> (params()->userWidth() * -areaWidthP1000);
else
userwidth = static_cast <int> (params()->userWidth() * areaWidthP1000);
//if ( userwidth < frontBarWidth ) {
points2.setPoint(0, excessRectNegative.topLeft().x(),points2.point(0).y());
points2.setPoint(2, excessRectNegative.topRight().x(),points2.point(2).y());
points2.setPoint(3, excessRectNegative.topRight().x(),points2.point(3).y());
points2.setPoint(5, excessRectNegative.topLeft().x(),points2.point(5).y());
}
painter->drawPolygon( points2 );
/*
NOTE: We do NOT want to store the region here, but
we use the front rectangle above in order to display the
data value labels inside the front rectangle.
Disadvantage: clicking onto these excess arrows, will not
result in a signal being sent, because KDChartWidget will
not notice, that the user has clicked onto the bar.
That's a minor drawback, compared to the gain of being
able to position the labels correctly.
*/
if ( cellValue < 0 )
points2.translate( 0, yArrowGap );
else
points2.translate( 0, -yArrowGap );
painter->drawPolygon( points2 );
/*
NOTE: We do NOT want to store the region here
(see comment above)
*/
}
}
painter->setClipRect( ourClipRect );
} /*if (tooLow && bNormalMode)*/
else {
//
// old code (sometimes not touching the grid):
//TQRect rec( xpos, yZero, frontBarWidth, -barHeight );
//painter->drawRect( rec );
//
int pt1Y = static_cast < int > ( yZero - barHeight /*- sideBarsHeight*/ );
/*
if ( cellValue != 0 ) {
pt1Y = static_cast <int> (cellValue * pixelsPerUnit * -2);
qDebug( "value %s",TQString::number(static_cast <int> (cellValue)).latin1());
qDebug( "pt1Y %s", TQString::number(static_cast <int> (cellValue * pixelsPerUnit * -2)).latin1());
}
else
pt1Y = static_cast < int > ( yZero - barHeight);
*/
calculateXFront1_2( bNormalMode, bIsVeryFirstBar, bIsFirstDataset, _bThreeDBars,
xpos, valueBlockGap, datasetGap, frontBarWidth,
frontX1, frontX2, prevFrontX2 );
TQPoint pt1( frontX1, pt1Y );
TQPoint pt2( frontX2,
static_cast < int > ( yZero + sideBarHeight) );
if( 0.0 > maxColumnValue ){
pt2.setY(pt2.y() - static_cast < int > (pixelsPerUnit * maxColumnValue));
}
if( pt2.y() < pt1Y ) {
pt1.setY( pt2.y() );
pt2.setY( pt1Y );
}
if( pt2.x() < frontX1 ) {
pt1.setX( frontX2 );
pt2.setX( frontX1 );
}
if( bDrawExtraLines ){
int y = pt2.y();
if( _bThreeDBars )
y -= static_cast < int > ( sideBarHeight );
drawExtraLinesAndMarkers(
propSet,
defaultPen,
defaultMarkerStyle,
(frontX1+frontX2)/2, y,
painter,
ai.abscissaPara,
ordinatePara,
areaWidthP1000,
logHeight/1000.0,
bDrawExtraLinesInFront );
}else if( bShowThisBar ){
TQSize siz( pt2.x() - pt1.x(),
pt2.y() - pt1.y() );
TQRect rect( pt1, siz );
if( 1.5 > frontBarWidth ){
TQPen oldPen( painter->pen() );
painter->setPen( TQPen(painter->brush().color(), 0) );
painter->drawLine(pt1, TQPoint(pt1.x(),pt2.y()));
painter->setPen( oldPen );
}else{
// store the front rect negative
if ( tooLow || cellValue < minColumnValue) {
frontRectNegative.setTopLeft(excessRectNegative.bottomLeft());
frontRectNegative.setTopRight(excessRectNegative.bottomRight());
frontRectNegative.setBottomRight(excessRectNegative.topRight());
frontRectNegative.setBottomLeft(excessRectNegative.topLeft());
} else {
frontRectNegative.setTopLeft(rect.topLeft());
frontRectNegative.setTopRight(rect.topRight());
frontRectNegative.setBottomRight(rect.bottomRight());
frontRectNegative.setBottomLeft(rect.bottomLeft());
if ( cellValue == 0 && params()->barChartSubType() == KDChartParams::BarPercent)
rect.setTop( rect.bottom());
}
//debug lines and points
/*
painter->drawLine( rect.topLeft(), rect.topRight());
painter->drawLine( rect.topRight(), rect.bottomRight());
painter->drawLine( rect.bottomRight(), rect.bottomLeft());
painter->drawLine( rect.bottomLeft(), rect.topLeft());
painter->drawText( frontRectNegative.topLeft(), "0f");
painter->drawText( frontRectNegative.topRight(), "1f");
painter->drawText( frontRectNegative.bottomRight(), "2f");
painter->drawText( frontRectNegative.bottomLeft(), "3f");
*/
//Pending Michel adjust the painting in case we have a user given Width
//and it is not larger than the auto calculated width
if ( params()->userWidth() != 0 ) {
int userwidth = 0;
if ( params()->userWidth() < 0 )
userwidth = static_cast <int> (params()->userWidth() * -areaWidthP1000);
else
userwidth = static_cast <int> (params()->userWidth() * areaWidthP1000);
//if ( userwidth < frontBarWidth ) {
rect.setLeft( static_cast <int> (rect.center().x() - (userwidth/2)));
rect.setRight( static_cast <int> (rect.center().x() + (userwidth/2)));
rect.setWidth( static_cast <int> (userwidth) );
frontRectNegative.setLeft( tooLow || cellValue < minColumnValue ?
static_cast <int> (excessRectNegative.center().x() - (userwidth/2)):rect.left());
frontRectNegative.setRight( tooHigh ? static_cast <int> (excessRectNegative.center().x() + (userwidth/2)):rect.right());
}
//drawing the front size negative values
if ( cellValue != 0 && params()->barChartSubType() != KDChartParams::BarPercent) {
painter->setClipping( false );
painter->drawRect( rect );
}
}
// Don't use rect for drawing after this!
if ( pointArrayList ) {
rect.moveBy( _dataRect.x(), _dataRect.y() );
pointArrayList->append( rectToPointArray( rect ) );
}
}
}
} else {
//
// Positive values:
//
/*Pending Michel: all values under the min value are handled as negative*/
double maxValueYPos = maxColumnValue * pixelsPerUnit;
double minValueYPos = minColumnValue * pixelsPerUnit;
double minDataValueYPos = maxValueYPos - minValueYPos;
double yZero = yposPositives - zeroXAxisI;
//qDebug( "yposPositives %f - zeroXAxisI %f = %f" , yposPositives, zeroXAxisI, yZero );
//qDebug( "yZero %s", TQString::number( yZero ).latin1());
//qDebug( "minDataValueYPos = %s", TQString::number( minDataValueYPos).latin1());
//qDebug( "positive value %s", TQString::number( cellValue).latin1());
//Pending Michel: draw the default split excess arrows
//when the front top of the 3d chart reach the max Y value
if(!_bThreeDBars)
tooHigh = ( barHeight > maxValueYPos*1.001 ) || ( cellValue < minColumnValue );
else {
//calculate the Y position for the top front line
//if it is over the max height pos - tooHigh becomes true
if ( params()->barChartSubType()!= KDChartParams::BarStacked ) {
int dataValueYPos = static_cast <int>( ( cellValue * pixelsPerUnit ) );
tooHigh = dataValueYPos > maxValueYPos;
} else {
tooHigh = maxValueInThisColumn > maxColumnValue;
}
}
if ( tooHigh && bNormalMode ||
tooHigh && params()->barChartSubType()== KDChartParams::BarStacked
|| tooHigh && bMultiRows ) {
double delta = -0.0125 * logHeight;
double height = -1.0 * yZero
- 2.0 * delta;
double height1 = height + -3.0 * delta;
int yArrowGap = static_cast < int > ( 2.5 * delta );
calculateXFront1_2( bNormalMode, bIsVeryFirstBar, bIsFirstDataset, _bThreeDBars,
xpos, valueBlockGap, datasetGap, frontBarWidth,
frontX1, frontX2, prevFrontX2 );
const int xm = static_cast < int > ( ( frontX1 + frontX2 ) / 2.0 );
TQRect rect( ourClipRect );
rect.setTop( static_cast<int>( rect.top() + 3 * delta ) );
rect.setHeight( static_cast<int>( rect.height() - 3 * delta ) );
painter->setClipRect( rect );
if( bDrawExtraLines ){
drawExtraLinesAndMarkers(
propSet,
defaultPen,
defaultMarkerStyle,
xm, static_cast<int>( yZero + height1 ),
painter,
ai.abscissaPara,
ordinatePara,
areaWidthP1000,
logHeight/1000.0,
bDrawExtraLinesInFront );
}else if( bShowThisBar ){
if( params()->drawSolidExcessArrows() ) {
// Draw solid excess arrows
TQPointArray points( 5 );
/*this works for positive config and 0 include config*/
points.setPoint( 0, frontX1,
(minDataValueYPos < static_cast <int> (yZero))?
static_cast <int> (minDataValueYPos-1):static_cast <int>(yZero));
points.setPoint( 1, frontX2,
(minDataValueYPos < static_cast <int> (yZero))?
static_cast <int> (minDataValueYPos-1):static_cast <int>(yZero));
points.setPoint( 2, frontX2, static_cast<int>( yZero + height1 - 3.0 * delta )
+ 2 * yArrowGap );
points.setPoint( 3, xm, static_cast<int>( yZero + height1 )
+ 2 * yArrowGap );
points.setPoint( 4, frontX1, static_cast<int>( yZero + height1 - 3.0 * delta )
+ 2 * yArrowGap );
/*case where start and end value are negatives */
if ( cellValue > maxColumnValue && 0 >= maxColumnValue ) {
points.setPoint( 0, frontX1,static_cast<int>( yZero + height1 - 3.0 * delta ) + 2 * yArrowGap);
points.setPoint( 1, frontX2,static_cast<int>( yZero + height1 - 3.0 * delta ) + 2 * yArrowGap);
}
//Pending Michel adjust the painting in case we have a user given Width
//allow it to be larger than the auto calculated width in case we want
//to overlap
if ( params()->userWidth() != 0 ) {
int userwidth = 0;
if ( params()->userWidth() < 0 )
userwidth = static_cast <int> (params()->userWidth() * -areaWidthP1000);
else
userwidth = static_cast <int> (params()->userWidth() * areaWidthP1000);
//if ( userwidth < frontBarWidth ) {
TQRect tmpRect ( points.point(0), points.point(2));
points.setPoint(0, static_cast <int>(tmpRect.center().x() - userwidth/2),
points.point(0).y());
points.setPoint(1, static_cast <int>(tmpRect.center().x() + userwidth/2),
points.point(1).y());
points.setPoint(2, static_cast <int>(tmpRect.center().x() + userwidth/2),
points.point(2).y());
points.setPoint(4, static_cast <int>(tmpRect.center().x() - userwidth/2),
points.point(4).y());
//}
}
if ( params()->barChartSubType() != KDChartParams::BarStacked ||
params()->barChartSubType() == KDChartParams::BarStacked && dataset != datasetEnd ) {
//drawing a single front in case it is too high
painter->setClipping( false );
painter->drawPolygon( points );
}
//correct the y position: displaying position for the value label
TQPoint tpLeft (points.point(4).x(), static_cast <int> (points.point(4).y() - yArrowGap));
TQPoint tpRight(points.point(2).x(), static_cast <int> (points.point(2).y() - yArrowGap));
//debugging points
/*
painter->drawText( points.point(0), "p0");
painter->drawText( points.point(1), "p1");
painter->drawText( points.point(2), "p2");
painter->drawText( points.point(3), "p3");
*/
//store the front rectangle
excessRectPositive.setTopLeft(tpLeft);
excessRectPositive.setTopRight(tpRight);
excessRectPositive.setBottomRight(points.point(1));
excessRectPositive.setBottomLeft(points.point(0));
// Don't use points for drawing after this!
if ( pointArrayList && params()->barChartSubType() != KDChartParams::BarStacked ) {
points.translate( _dataRect.x(), _dataRect.y() + excessRectPositive.top() - yArrowGap );
pointArrayList->append( points );
} else if ( params()->barChartSubType() == KDChartParams::BarStacked ) {
if ( dataset != datasetEnd ) {
points.translate( _dataRect.x(), _dataRect.y() + excessRectPositive.top() );
pointArrayList->append( points );
} else {
//adjust the display of the value label under Y max value level
points.translate( _dataRect.x(), _dataRect.y() - excessRectPositive.bottom() - yArrowGap);
pointArrayList->append( points );
}
}
} else {
// Draw split excess arrows (default)
/* PENDING Michel:
* Here we have two situations.
* The value is too high because over the Max positive value
* or it is not within the configured view.
*/
TQPointArray points( 5 );
/*this works for positive config and 0 include config*/
points.setPoint( 0, frontX1,
(minDataValueYPos < static_cast <int> (yZero))?
static_cast <int> (minDataValueYPos - 1) : static_cast <int>(yZero));
points.setPoint( 1, frontX2,
(minDataValueYPos < static_cast <int> (yZero))?
static_cast<int> ( minDataValueYPos - 1) : static_cast <int>(yZero));
points.setPoint( 2, frontX2, static_cast<int>( yZero + height1 - 3.0 * delta ) );
points.setPoint( 3, xm, static_cast<int>( yZero + height1 ) );
points.setPoint( 4, frontX1, static_cast<int>( yZero + height1 - 3.0 * delta ) );
/*case where start and end value are negatives */
if ( cellValue > maxColumnValue && 0 >= maxColumnValue || cellValue == 0) {
points.setPoint( 0, frontX1, static_cast<int>( yZero + height1 - 3.0 * delta ));
points.setPoint( 1, frontX2, static_cast<int>( yZero + height1 - 3.0 * delta ));
}
//Pending Michel adjust the painting in case we have a user given Width
//allow it to be larger than the auto calculated width in case we want
//to overlap
if ( params()->userWidth() != 0 ) {
int userwidth = 0;
if ( params()->userWidth() < 0 )
userwidth = static_cast <int> (params()->userWidth() * -areaWidthP1000);
else
userwidth = static_cast <int> (params()->userWidth() * areaWidthP1000);
//if ( userwidth < frontBarWidth ) {
TQRect tmpRect ( points.point(0), points.point(2));
points.setPoint(0, static_cast <int>(tmpRect.center().x() - userwidth/2),
points.point(0).y());
points.setPoint(1, static_cast <int>(tmpRect.center().x() + userwidth/2),
points.point(1).y());
points.setPoint(2, static_cast <int>(tmpRect.center().x() + userwidth/2),
points.point(2).y());
points.setPoint(4, static_cast <int>(tmpRect.center().x() - userwidth/2),
points.point(4).y());
//}
}
if ( params()->barChartSubType() != KDChartParams::BarStacked ||
params()->barChartSubType() == KDChartParams::BarStacked && dataset != datasetEnd ) {
painter->setClipping( false );
painter->drawPolygon( points );
}
//store the front rectangle
excessRectPositive.setTopLeft(points.point(4));
excessRectPositive.setTopRight(points.point(2));
excessRectPositive.setBottomRight(points.point(1));
excessRectPositive.setBottomLeft(points.point(0));
// Don't use points for drawing after this!
if ( pointArrayList && params()->barChartSubType() != KDChartParams::BarStacked ) {
points.translate( _dataRect.x(), _dataRect.y() + excessRectPositive.top() );
pointArrayList->append( points );
} else if ( params()->barChartSubType() == KDChartParams::BarStacked ) {
if ( dataset != datasetEnd ) {
points.translate( _dataRect.x(), _dataRect.y() + excessRectPositive.top() );
pointArrayList->append( points );
} else {
//adjust the display of the value label under Y max value level
points.translate( _dataRect.x(), _dataRect.y() - excessRectPositive.bottom() - yArrowGap);
pointArrayList->append( points );
}
}
TQPointArray points2( 6 );
points2.setPoint( 0, frontX1, static_cast<int>( yZero + height1 - 3.0 * delta ) );
points2.setPoint( 1, xm, static_cast<int>( yZero + height1 ) );
points2.setPoint( 2, frontX2, static_cast<int>( yZero + height1 - 3.0 * delta ) );
points2.setPoint( 3, frontX2, static_cast<int>( yZero + height1 - 3.75 * delta ) );
points2.setPoint( 4, xm, static_cast<int>( yZero + height1 - 0.75 * delta ) );
points2.setPoint( 5, frontX1, static_cast<int>( yZero + height1 - 3.75 * delta ) );
points2.translate( 0, yArrowGap );
//Pending Michel adjust the painting in case we have a user given Width
//allow it to be larger than the auto calculated width in case we want
//to overlap
if ( params()->userWidth() != 0 ) {
int userwidth = 0;
if ( params()->userWidth() < 0 )
userwidth = static_cast <int> (params()->userWidth() * -areaWidthP1000);
else
userwidth = static_cast <int> (params()->userWidth() * areaWidthP1000);
//if ( userwidth < frontBarWidth ) {
points2.setPoint(0, excessRectPositive.topLeft().x(),points2.point(0).y());
points2.setPoint(2, excessRectPositive.topRight().x(),points2.point(2).y());
points2.setPoint(3, excessRectPositive.topRight().x(),points2.point(3).y());
points2.setPoint(5, excessRectPositive.topLeft().x(),points2.point(5).y());
//}
}
painter->drawPolygon( points2 );
/*
NOTE: We do NOT want to store the region here, but
we use the front rectangle above in order to display the
data value labels inside the front rectangle.
Disadvantage: clicking onto these excess arrows, will not
result in a signal being sent, because KDChartWidget will
not notice, that the user has clicked onto the bar.
That's a minor drawback, compared to the gain of being
able to position the labels correctly.
*/
points2.translate( 0, yArrowGap );
painter->drawPolygon( points2 );
/*
NOTE: We do NOT want to store the region here
(see comment above)
*/
} // draw split excess arrow
} //if( bShowThisBar )
painter->setClipRect( ourClipRect );
} // not tooLow && bNormalMode )
else {
//bool fromBottom = bNormalMode && !_bThreeDBars;
double y0 = yposPositives - zeroXAxisI;
int pt1Y = static_cast < int > ( y0 - barHeight - sideBarHeight);
calculateXFront1_2( bNormalMode, bIsVeryFirstBar, bIsFirstDataset, _bThreeDBars,
xpos, valueBlockGap, datasetGap, frontBarWidth,
frontX1, frontX2, prevFrontX2 );
TQPoint pt1( frontX1, pt1Y );
TQPoint pt2( frontX2,
static_cast < int > ( y0 + shiftUpperBars ) );
if( 0.0 < minColumnValue )
pt2.setY(pt2.y() - static_cast < int > ( pixelsPerUnit * minColumnValue ));
if( pt2.y() < pt1Y ) {
pt1.setY( pt2.y() );
pt2.setY( pt1Y );
}
if( pt2.x() < frontX1 ) {
pt1.setX( frontX2 );
pt2.setX( frontX1 );
}
if( bDrawExtraLines ){
int y = pt1.y();
if( _bThreeDBars )
y -= static_cast < int > ( sideBarHeight );
drawExtraLinesAndMarkers(
propSet,
defaultPen,
defaultMarkerStyle,
(frontX1+frontX2)/2, y,
painter,
ai.abscissaPara,
ordinatePara,
areaWidthP1000,
logHeight/1000.0,
bDrawExtraLinesInFront );
}else if( bShowThisBar ){
TQSize siz( pt2.x() - pt1.x(),
pt2.y() - pt1.y());
TQRect rect( pt1, siz );
//adjust display for the 3d percent bars - last dataset.
if ( params()->barChartSubType() == KDChartParams::BarPercent && cellValue != 0)
rect.setTop( rect.top() + static_cast <int> (sideBarHeight) - 1);
// store the front rect
if( tooHigh ) {
frontRectPositive.setTopLeft(excessRectPositive.topLeft());
frontRectPositive.setTopRight(excessRectPositive.topRight());
frontRectPositive.setBottomRight(excessRectPositive.bottomRight());
frontRectPositive.setBottomLeft(excessRectPositive.bottomLeft());
} else {
frontRectPositive.setTopLeft(rect.topLeft());
frontRectPositive.setTopRight(rect.topRight());
frontRectPositive.setBottomRight(rect.bottomRight());
frontRectPositive.setBottomLeft(rect.bottomLeft());
if( _bThreeDBars && cellValue == 0 )
frontRectNegative = frontRectPositive;
}
if( 1.5 > frontBarWidth ){
//qDebug("1.5 > frontBarWidth ");
TQPen oldPen( painter->pen() );
painter->setPen( TQPen(painter->brush().color(), 0) );
painter->drawLine(pt1, TQPoint(pt1.x(),pt2.y()));
painter->setPen( oldPen );
}else{
//debugging points and lines
/*
painter->drawText( rect.topLeft(), TQString::number(cellValue).latin1());
painter->drawText( rect.topRight(), "1f");
painter->drawText( rect.bottomRight(), "2f");
painter->drawText( rect.bottomLeft(), "3f");
painter->drawLine( rect.topLeft(), rect.topRight());
painter->drawLine( rect.topRight(), rect.bottomRight());
painter->drawLine( rect.bottomRight(), rect.bottomLeft());
painter->drawLine( rect.bottomLeft(), rect.topLeft());
*/
//Pending Michel adjust the painting in case we have a user given Width
//allow it to be larger than the auto calculated width in case we want
//to overlap
if ( params()->userWidth() != 0 ) {
int userwidth = 0;
if ( params()->userWidth() < 0 )
userwidth = static_cast <int> (params()->userWidth() * -areaWidthP1000);
else
userwidth = static_cast <int> (params()->userWidth() * areaWidthP1000);
//if ( userwidth < frontBarWidth ) {
rect.setLeft( static_cast <int> (rect.center().x() - (userwidth/2)));
rect.setRight( static_cast <int> (rect.center().x() + (userwidth/2)));
rect.setWidth( static_cast <int> (userwidth) );
//adjust the front rect
frontRectPositive.setLeft( tooHigh ? static_cast <int> (excessRectPositive.center().x() - (userwidth/2)):rect.left());
frontRectPositive.setRight( tooHigh ? static_cast <int> (excessRectPositive.center().x() + (userwidth/2)):rect.right());
}
// drawing the front side
if (!tooHigh && !tooLow || params()->barChartSubType() == KDChartParams::BarPercent ) {
if ( bMultiRows )
painter->setClipping( false );
else
painter->setClipping( true );
painter->drawRect( rect );
}
// Don't use rect for drawing after this
if ( pointArrayList ) {
rect.moveBy( _dataRect.x(), _dataRect.y());
pointArrayList->append( rectToPointArray( rect ) );
}
}
} // bShowThisBar
} // positive values
}
if ( bShowThisBar && _bThreeDBars && !bDrawExtraLines ) {
//Pending Michel: no need to use that anymore
//const int maxY = 2*devRect.height();
TQPointArray points( 4 );
if (cellValue <= 0 || cellValue < minColumnValue) {
if ( tooLow || cellValue < minColumnValue ) {
points.setPoint(0, excessRectNegative.topRight());
points.setPoint(1, excessRectNegative.topRight().x() + static_cast<int>(sideBarHeight),
excessRectNegative.top() - static_cast<int>(sideBarHeight));
points.setPoint(2, excessRectNegative.bottomRight().x() + static_cast<int>(sideBarHeight),
excessRectNegative.bottom() - static_cast<int>(sideBarHeight));
points.setPoint(3, excessRectNegative.bottomRight());
} else {
points.setPoint( 0, frontRectNegative.bottomRight());
points.setPoint( 1, frontRectNegative.bottomRight().x() + static_cast<int>(sideBarHeight),
frontRectNegative.bottom() - static_cast<int>(sideBarHeight) );
points.setPoint(2, frontRectNegative.bottomRight().x() + static_cast<int>(sideBarHeight),
frontRectNegative.top() - static_cast<int>(sideBarHeight));
points.setPoint(3, frontRectNegative.topRight() );
}
rightRectNegative.setTopLeft( points.point(0));
rightRectNegative.setTopRight( points.point(2));
rightRectNegative.setBottomRight(points.point(1));
rightRectNegative.setBottomLeft(points.point(3));
} else {
// Pending Michel
// Make sure to align the right side top and bottom points
// to the front side points
if ( tooHigh ) {
points.setPoint(0, excessRectPositive.topRight());
points.setPoint(1, excessRectPositive.topRight().x() + static_cast <int> (sideBarHeight),
excessRectPositive.top() - static_cast <int> (sideBarHeight) );
points.setPoint(2, excessRectPositive.bottomRight().x() + static_cast <int> (sideBarHeight),
excessRectPositive.bottom() - static_cast <int> (sideBarHeight));
points.setPoint(3, excessRectPositive.bottomRight());
} else {
points.setPoint(0, frontRectPositive.topRight());
points.setPoint(1, frontRectPositive.topRight().x() + static_cast <int> (sideBarHeight),
frontRectPositive.top() - static_cast<int>(sideBarHeight));
points.setPoint(2, frontRectPositive.bottomRight().x() + static_cast <int> (sideBarHeight),
frontRectPositive.bottom() - static_cast<int>(sideBarHeight));
points.setPoint(3, frontRectPositive.bottomRight());
}
//register the right rect
rightRectPositive.setTopLeft( points.point(0));
rightRectPositive.setTopRight( points.point(1));
rightRectPositive.setBottomLeft( points.point(3));
rightRectPositive.setBottomRight(points.point(2));
}
if ( myShadow2Color.isValid() )
painter->setBrush( TQBrush( myShadow2Color, params()->shadowPattern() ) );
else
painter->setBrush( NoBrush );
//debug points and lines
/*
painter->drawText( points.point(0), "0r");
painter->drawText( points.point(1), "1r");
painter->drawText( points.point(2), "2r");
painter->drawText( points.point(3), "3r");
painter->drawLine( points.point(0), points.point(1));
painter->drawLine( points.point(1), points.point(2));
painter->drawLine( points.point(2), points.point(3));
painter->drawLine( points.point(3), points.point(0));
*/
//drawing the right side
if( (!tooHigh && !tooLow) || (tooHigh && cellValue <= 0 ) ) {
if (( cellValue != 0 && params()->barChartSubType() == KDChartParams::BarPercent ) ||
( cellValue != 0 && params()->barChartSubType() == KDChartParams::BarStacked ) ||
( cellValue != 0 && bNormalMode ||
cellValue != 0 && bMultiRows)) {
painter->setClipping( false );
painter->drawPolygon( points );
}
}
// Dont override the region stored in case of excess values or barPercent this in order to display
// the value labels closer to the corner of the front bar.
if ( pointArrayList && !tooHigh && !tooLow && params()->barChartSubType() != KDChartParams::BarPercent ) {
TQPointArray points2cpy( points.copy() );
//qDebug("g2");
points2cpy.translate( _dataRect.x(), _dataRect.y());
//qDebug("g3");
pointArrayList->append( points2cpy );
//qDebug("g4");
}
// drawing the top, but only for the topmost piece for stacked and percent
if ( bNormalMode || bMultiRows ||
// For stacked and percent bars, there are three ways to determine
// the top:
// 1. all values are negative: the top is the one in the first dataset
( maxValueInThisColumn <= 0.0 && dataset == firstValidValue ) ||
// 2. all values are positive: the top is the one in the last dataset
( minValueInThisColumn >= 0.0 && dataset == lastValidPositiveValue ) ||
// 3. some values are positive, some negative:
// the top is the one in the last positive
// dataset value
( dataset == lastValidPositiveValue ) ) {
if (cellValue <= 0 || cellValue < minColumnValue) {
if ( tooLow ) {
points.setPoint(0,excessRectNegative.bottomLeft());
points.setPoint(1,excessRectNegative.topLeft().x() + static_cast <int> (sideBarHeight),
excessRectNegative.bottom() - static_cast <int> (sideBarHeight));
points.setPoint(2,excessRectNegative.bottomRight().x() + static_cast <int> (sideBarHeight),
excessRectNegative.bottom() - static_cast <int> (sideBarHeight));
points.setPoint(3,excessRectNegative.bottomRight());
}else {
// Align the top to the front and the right side
points.setPoint(0,frontRectNegative.topLeft() );
points.setPoint(1,frontRectNegative.topLeft().x() + static_cast <int> (sideBarHeight), rightRectNegative.top());
points.setPoint(2,rightRectNegative.topRight() );
points.setPoint(3,rightRectNegative.topRight().x() - static_cast <int> (sideBarHeight),
frontRectNegative.topRight().y() );
//make sure the top rect color is the right one - barStacked - Noll values
if ( (params()->barChartSubType() == KDChartParams::BarStacked && cellValue == 0 && maxValueInThisColumn != 0 ) )
points.translate(0, maxValueInThisColumn <= 0?-(static_cast <int> (1*pixelsPerUnit) + 1):
-static_cast<int>(maxValueInThisColumn*pixelsPerUnit));
if ( params()->barChartSubType() == KDChartParams::BarPercent && cellValue == 0 ) {
if ( dataset == datasetEnd && maxValueInThisColumn != 0)
points.translate(0, -static_cast<int>( logHeight - sideBarHeight ));
else if ( maxValueInThisColumn == 0)
points.translate(0, static_cast <int> (logHeight + (sideBarHeight - sideBarWidth)));
}
}
} else {
if ( tooHigh ) {
points.setPoint(0, excessRectPositive.topLeft());
points.setPoint(1, excessRectPositive.topLeft().x() + static_cast <int> (sideBarHeight),
excessRectPositive.top() - static_cast <int> (sideBarHeight) );
points.setPoint(2, excessRectPositive.topRight().x() + static_cast <int> (sideBarHeight),
excessRectPositive.top() - static_cast <int> (sideBarHeight));
points.setPoint(3, excessRectPositive.topRight());
} else {
// Pending Michel
// Align the top to the front and the right side
points.setPoint(0, frontRectPositive.topLeft());
points.setPoint(1, frontRectPositive.topLeft().x() + static_cast <int> (sideBarHeight),
rightRectPositive.top() );
points.setPoint(2, rightRectPositive.topRight());
points.setPoint(3, rightRectPositive.topRight().x() - static_cast <int> (sideBarHeight),
frontRectPositive.topRight().y());
}
}
if (cellValue < 0.0 && maxValueInThisColumn < 0)
painter->setBrush( bMultiRows ? myBarColor : black );
else
painter->setBrush( TQBrush( myShadow1Color, params()->shadowPattern() ) );
if ( !myShadow1Color.isValid() )
painter->setBrush( NoBrush ); // override prev. setting
// debug points and lines
/*
painter->drawText( points.point(0), "0t");
painter->drawText( points.point(1), "1t");
painter->drawText( points.point(2), "2t");
painter->drawText( points.point(3), "3t");
painter->drawLine( points.point(0), points.point(1) );
painter->drawLine( points.point(1),points.point(2) );
painter->drawLine( points.point(2),points.point(3) );
painter->drawLine( points.point(3),points.point(0) );
*/
// drawing the top side
if (!tooHigh && !tooLow || (tooHigh && cellValue <= 0) )
painter->drawPolygon( points );
// dont override the region stored in case of excess values.
if (pointArrayList && !tooHigh && !tooLow
&& params()->barChartSubType() != KDChartParams::BarPercent
&& params()->barChartSubType() != KDChartParams::BarStacked) {
points.translate( _dataRect.x(), _dataRect.y());
pointArrayList->append( points );
}
}
}//if ( _bThreeDBars )
if( regions && pointArrayList && ! pointArrayList->empty() ) {
if( bShowThisBar && !bDrawExtraLines ){
KDChartDataRegion * region;
if( _bThreeDBars ){
region = new KDChartDataRegion( dataset, value, chart,
pointArrayList, true );
} else {
// just store a rectangle if NOT in 3-D bar mode
region = new KDChartDataRegion( dataset, value, chart,
TQT_TQRECT_OBJECT(pointArrayList->first().boundingRect()) );
delete pointArrayList;
}
/*qDebug("KDChartDataRegion stored! x: %i y: %i w: %i h: %i",
region->rect().x(),region->rect().y(),
region->rect().width(),region->rect().height());*/
regions->append( region );
} else {
delete pointArrayList;
}
}
}// if( !bDrawExtraLines || bCellPropertiesFound )
}// if( !skipMe )
}else{
// Do not paint a bar, but update the position
// variable: to find the exact x1 position for
// the next bar that will be drawn.
int iDummy1, iDummy2;
calculateXFront1_2( bNormalMode, bIsVeryFirstBar, bIsFirstDataset, _bThreeDBars,
xpos, valueBlockGap, datasetGap, frontBarWidth,
iDummy1, iDummy2, prevFrontX2 );
}// if( dataset >= datasetStart && dataset <= datasetEnd )
//Qt::Vertical advancement in stacked or percent only if there was a value
// Pending Michel add sideBarHeight in case we are in 3D mode but not for Percent
// where we need to display the top rect but cant resize the YAxis.
if ( params()->barChartSubType() == KDChartParams::BarStacked ||
params()->barChartSubType() == KDChartParams::BarPercent )
if ( /*barHeight*/ cellValue < 0 )
(_bThreeDBars && params()->barChartSubType() != KDChartParams::BarPercent)?yposNegatives -= sideBarHeight + barHeight:
yposNegatives -= barHeight;
else
(_bThreeDBars && params()->barChartSubType() != KDChartParams::BarPercent)?yposPositives -= sideBarHeight + barHeight:
yposPositives -= barHeight;
} else {
// Do not paint a bar, but update the position
// variable: to find the exact x1 position for
// the next bar that will be drawn.
int iDummy1, iDummy2;
calculateXFront1_2( bNormalMode, bIsVeryFirstBar, bIsFirstDataset, _bThreeDBars,
xpos, valueBlockGap, datasetGap, frontBarWidth,
iDummy1, iDummy2, prevFrontX2 );
}
// advance only if the next dataset has DataEntry mode
bool bAdvanceToNextValue =
( bMultiRows ? (dataset == chartDatasetStart) : (dataset == chartDatasetEnd)
|| ( params()->chartSourceMode( bMultiRows ? dataset-1 : dataset+1 )
== KDChartParams::DataEntry ) );
// Advance to next value; only for normal bars
if ( bNormalMode ) {
if( bAdvanceToNextValue )
xpos += barWidth;
// skip gap between datasets, unless last dataset
if ( dataset < myLastDataEntryDataset )
xpos += datasetGap;
}
if( bAdvanceToNextValue || bMultiRows ){
//qDebug("shiftMyPainter( -nShiftX, nShiftY );");
shiftMyPainter( -nShiftX, nShiftY );
}
bIsVeryFirstBar = false;
bIsFirstDataset = false;
}
// Advancement between value blocks
if ( bNormalMode ){
// skip gap between value blocks, don't worry about last one here
xpos += valueBlockGap;
//qDebug("**************************** xpos: %f + valueBlockGap: %f = %f", xpos, valueBlockGap, xpos+valueBlockGap);
}else{
// skip gap between value blocks
xpos += valueBlockGap + barWidth;
//qDebug ( "2/ barWidth %f", barWidth );
//qDebug ( " valueBlockGap %f", valueBlockGap );
// start at bottom with next value group
yposPositives = yposPositivesStart;
yposNegatives = yposNegativesStart;
}
//qDebug("shiftMyPainterBack");
shiftMyPainterBack();
}
}
if( bMultiRows )
painter->setClipping( bHadClipping );
}
|