29#include "KDChartHiLoPainter.h"
31#include "KDChartTextPiece.h"
80 return TQObject::tr(
"Value " ) + TQString::number( dataset + 1 );
99bool KDChartHiLoPainter::isNormalMode()
const
104int KDChartHiLoPainter::clipShiftUp(
bool,
double )
const
109void KDChartHiLoPainter::specificPaintData( TQPainter* painter,
110 const TQRect& ourClipRect,
117 double areaWidthP1000,
123 uint chartDatasetStart,
124 uint chartDatasetEnd,
128 double areaHeightP1000 = logHeight / 1000.0;
129 double averageValueP1000 = ( areaWidthP1000 + areaHeightP1000 ) / 2.0;
130 int datasetNum=abs(
static_cast<int>(chartDatasetEnd-chartDatasetStart))+1;
132 painter->setPen( params()->outlineDataColor() );
137 if ( params()->numValues() != -1 )
138 numValues = params()->numValues();
144 if( (numValues < 2) ||
145 ((params()->hiLoChartSubType() == KDChartParams::HiLoClose) && (numValues < 3)) ||
146 ((params()->hiLoChartSubType() == KDChartParams::HiLoOpenClose) && (numValues < 4)) ){
147 tqDebug(
"\nNot enough data to display a High/Low Chart!\n" );
148 tqDebug(
"type requiring" );
149 tqDebug(
"---- ---------" );
150 tqDebug(
"High/Low 2 data cells per series" );
151 tqDebug(
"High/Low/Close 3 data cells per series" );
152 tqDebug(
"High/Low/open/Close 4 data cells per series\n" );
156 double pixelsPerUnit = 0.0;
160 pixelsPerUnit = logHeight / 10;
163 double pointDist = logWidth / (double)datasetNum;
168 const int nLineWidth = params()->lineWidth();
171 for ( uint dataset = chartDatasetStart;
172 dataset <= chartDatasetEnd;
178 if( dataset >= datasetStart &&
179 dataset <= datasetEnd &&
180 data->
cellCoord( dataset, 0, valueA, 1 ) &&
181 data->
cellCoord( dataset, 1, valueB, 1 ) &&
182 TQVariant::Double == valueA.type() &&
183 TQVariant::Double == valueB.type() ){
184 const double cellValue1 = valueA.toDouble();
185 const double cellValue2 = valueB.toDouble();
186 const double lowValue = TQMIN( cellValue1, cellValue2 );
187 const double highValue = TQMAX( cellValue1, cellValue2 );
188 const double lowDrawValue = lowValue * pixelsPerUnit;
189 const double highDrawValue = highValue * pixelsPerUnit;
191 painter->setPen( TQPen( params()->dataColor( dataset ),
194 int xpos =
static_cast<int>(
195 pointDist * ( (double)(dataset-chartDatasetStart) + 0.5 ) );
196 int lowYPos =
static_cast<int>( zeroXAxisI - lowDrawValue );
197 int highYPos =
static_cast<int>( zeroXAxisI - highDrawValue );
199 painter->drawLine( xpos, lowYPos, xpos, highYPos );
204 int openCloseTickLength =
static_cast<int>( pointDist * 0.1 );
207 bool hasOpen =
false, hasClose =
false;
208 double openValue = 0.0, openDrawValue = 0.0,
209 closeValue = 0.0, closeDrawValue = 0.0;
212 if( params()->hiLoChartSubType() == KDChartParams::HiLoOpenClose ) {
214 if( data->
cellCoord( dataset, 2, valueA, 1 ) &&
215 TQVariant::Double == valueA.type() ) {
217 openValue = valueA.toDouble();
218 openDrawValue = openValue * pixelsPerUnit;
219 painter->drawLine( xpos - openCloseTickLength,
220 static_cast<int>( zeroXAxisI - openDrawValue ),
222 static_cast<int>( zeroXAxisI - openDrawValue ) );
230 if( ( params()->hiLoChartSubType() == KDChartParams::HiLoClose &&
231 data->
cellCoord( dataset, 2, valueA, 1 ) &&
232 TQVariant::Double == valueA.type() ) ||
233 ( params()->hiLoChartSubType() == KDChartParams::HiLoOpenClose &&
234 data->
cellCoord( dataset, 3, valueB, 1 ) &&
235 TQVariant::Double == valueB.type() ) ) {
237 closeValue = ( params()->hiLoChartSubType() == KDChartParams::HiLoClose )
240 closeDrawValue = closeValue * pixelsPerUnit;
241 painter->drawLine( xpos,
242 static_cast<int>( zeroXAxisI - closeDrawValue ),
243 xpos + openCloseTickLength,
244 static_cast<int>( zeroXAxisI - closeDrawValue ) );
248 if( params()->hiLoChartPrintLowValues() ) {
250 TQFont theFont( params()->hiLoChartLowValuesFont() );
251 if ( params()->hiLoChartLowValuesUseFontRelSize() ) {
253 static_cast < int > ( params()->hiLoChartLowValuesFontRelSize()
254 * averageValueP1000 );
255 theFont.setPointSizeFloat( nTxtHeight );
257 KDChartTextPiece lowText( painter, TQString::number( lowValue ),
259 int width = lowText.width();
260 int height = lowText.height();
263 int valX = 0, valY = 0;
267 if( zeroXAxisI - lowDrawValue + height < axisYOffset+logHeight ) {
269 valX = xpos - ( width / 2 );
270 valY = (int)lowDrawValue - lowText.fontLeading();
273 if( !hasOpen || height < openDrawValue ) {
276 valX = xpos - width - nLineWidth;
277 valY =
static_cast<int>(zeroXAxisI)
284 lowText.draw( painter,
285 valX,
static_cast<int>( zeroXAxisI - valY ),
287 params()->hiLoChartLowValuesColor() );
291 if( params()->hiLoChartPrintHighValues() ) {
293 TQFont theFont( params()->hiLoChartHighValuesFont() );
294 if ( params()->hiLoChartHighValuesUseFontRelSize() ) {
296 static_cast < int > ( params()->hiLoChartHighValuesFontRelSize()
297 * averageValueP1000 );
298 theFont.setPointSizeFloat( nTxtHeight );
300 KDChartTextPiece highText( painter, TQString::number( highValue ),
302 int width = highText.width();
303 int height = highText.height();
306 int valX = 0, valY = 0;
307 if( zeroXAxisI - highDrawValue - height > axisYOffset ) {
309 valX = xpos - ( width / 2 );
310 valY = (int)highDrawValue + highText.fontLeading() + height;
314 height < ( _dataRect.height() - closeDrawValue ) ) {
317 valX = xpos + nLineWidth;
318 valY =
static_cast<int>(zeroXAxisI)
325 highText.draw( painter,
326 valX,
static_cast<int>( zeroXAxisI - valY ),
328 params()->hiLoChartHighValuesColor() );
332 if( params()->hiLoChartPrintOpenValues() &&
333 params()->hiLoChartSubType() == KDChartParams::HiLoOpenClose ) {
335 TQFont theFont( params()->hiLoChartOpenValuesFont() );
336 if ( params()->hiLoChartOpenValuesUseFontRelSize() ) {
338 static_cast < int > ( params()->hiLoChartOpenValuesFontRelSize()
339 * averageValueP1000 );
340 theFont.setPointSizeFloat( nTxtHeight );
342 KDChartTextPiece openText( painter, TQString::number( openValue ),
344 int width = openText.width();
345 int height = openText.height();
349 int valX = 0, valY = 0;
350 valX = xpos - openCloseTickLength - width;
351 valY = (int)openDrawValue + ( height / 2 );
352 openText.draw( painter,
353 valX,
static_cast<int>( zeroXAxisI - valY ),
355 params()->hiLoChartOpenValuesColor() );
359 if( params()->hiLoChartPrintCloseValues() &&
360 ( params()->hiLoChartSubType() == KDChartParams::HiLoOpenClose
362 params()->hiLoChartSubType() == KDChartParams::HiLoClose ) ) {
364 TQFont theFont( params()->hiLoChartCloseValuesFont() );
365 if ( params()->hiLoChartCloseValuesUseFontRelSize() ) {
367 static_cast < int > ( params()->hiLoChartCloseValuesFontRelSize()
368 * averageValueP1000 );
369 theFont.setPointSizeFloat( nTxtHeight );
371 KDChartTextPiece closeText( painter, TQString::number( closeValue ),
374 int height = closeText.height();
378 int valX = 0, valY = 0;
379 valX = xpos + openCloseTickLength;
380 valY = (int)closeDrawValue + ( height / 2 );
381 closeText.draw( painter,
382 valX,
static_cast<int>( zeroXAxisI - valY ),
384 params()->hiLoChartCloseValuesColor() );
Header for all common chart parameters.
KDChartAxesPainter(KDChartParams *params)
Constructor.
access the chart axis parameters.
double trueAxisHigh() const
Returns the true end value of the ordinate axis labels as is was calculated and set by setTrueAxisLow...
double trueAxisLow() const
Returns the true start value of the ordinate axis labels as is was calculated and set by setTrueAxisL...
double axisZeroLineStartY() const
Returns the not-rounded y-position where drawing of this axis zero line started.
The collection class used by KD Chart to store data region information.
virtual TQString fallbackLegendText(uint dataset) const
This method is a specialization that returns a fallback legend text appropriate for HiLo that do not ...
virtual uint numLegendFallbackTexts(KDChartTableDataBase *data) const
This methods returns the number of elements to be shown in the legend in case fallback texts are used...
KDChartHiLoPainter(KDChartParams *params)
Constructor.
virtual ~KDChartHiLoPainter()
Destructor.
Bundles the display parameters of a chart.
HiLoChartSubType hiLoChartSubType() const
Returns the HiLo chart subtype.
KD Chart's build-in table data for an easy way of storing data values.
virtual uint usedCols() const
Returns the number of cols in the table that actually contain data.
virtual bool cellCoord(uint _row, uint _col, TQVariant &_value, int coordinate=1) const =0
Returns one of the coordinate data value(s) stored in a cell.
virtual uint usedRows() const
Returns the number of rows in the table that actually contain data.