[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice
Subject: A function addition and bug fix patch of KChart
From: Toshitaka Fujioka <tositaka () soft ! kusa ! ac ! jp>
Date: 2001-01-10 3:23:40
[Download RAW message or body]
Hello.
I made the patch which display "legend" with colored character.
A screen shot. http://www.kusa.ac.jp/~tositaka/kchart.jpg
I made the patch which fixed bug that "X Title" was displayed
with a pie graph.
(CVS of 05/01)
I attached a patch.
Please try to use.
["koffice-kchart-FunctionAddition-20010109.diff" (text/plain)]
diff -ur koffice.org/kchart/engine.cc koffice/kchart/engine.cc
--- koffice.org/kchart/engine.cc Tue Jan 9 20:45:17 2001
+++ koffice/kchart/engine.cc Tue Jan 9 21:39:25 2001
@@ -118,7 +118,8 @@
if(!params->isPie()) {
drawGridAndLabels(do_ylbl_fractions);
kdDebug(35001) << "more advanced grids" << endl;
- }
+ drawLegendAndColors();
+ }
/* intervening set grids */
/* 0 < setno < num_sets non-inclusive, they've already been covered */
if( params->grid && params->threeD() && !params->isPie())
diff -ur koffice.org/kchart/kchartEngine.cc koffice/kchart/kchartEngine.cc
--- koffice.org/kchart/kchartEngine.cc Tue Jan 9 20:45:17 2001
+++ koffice/kchart/kchartEngine.cc Tue Jan 9 21:39:26 2001
@@ -56,6 +56,9 @@
num_points = data->cols(); //data->usedCols();
+ // And num_points_row is the number of rows
+ num_points_rows = data->rows();
+
/* idiot checks */
if( imagewidth <= 0 || imageheight <=0 || !p )
return -1;
diff -ur koffice.org/kchart/kchartEngine.h koffice/kchart/kchartEngine.h
--- koffice.org/kchart/kchartEngine.h Tue Jan 9 20:45:17 2001
+++ koffice/kchart/kchartEngine.h Tue Jan 9 21:39:26 2001
@@ -20,6 +20,7 @@
int compute_yintervals();
void titleText();
+ void drawLegendAndColors();
void drawBorder();
void drawAnnotation();
void drawThumbnails();
@@ -70,6 +71,7 @@
int num_sets;
int num_hlc_sets;
int num_points;
+ int num_points_rows;
int graphwidth;
int graphheight;
float xorig, yorig, vyorig;
diff -ur koffice.org/kchart/kchartEngine2.cc koffice/kchart/kchartEngine2.cc
--- koffice.org/kchart/kchartEngine2.cc Tue Jan 9 20:45:17 2001
+++ koffice/kchart/kchartEngine2.cc Tue Jan 9 21:46:19 2001
@@ -79,6 +79,9 @@
void KChartEngine::titleText() {
if( !params->title.isEmpty() )
{
+ if (params->isPie())
+ params->legend_wth = 0;
+
int tlen=0;
QColor titlecolor = params->TitleColor;
cnt_nl( (const char*)params->title.local8Bit(), &tlen );
@@ -89,7 +92,7 @@
MAXINT,
Qt::AlignCenter,
params->title );
- p->drawText( imagewidth/2 - tlen*params->titleFontWidth()/2, // x
+ p->drawText( (imagewidth/2 - tlen*params->titleFontWidth()/2) + \
params->legend_wth, // x 0, // y
br.width(), br.height(),
Qt::AlignCenter, params->title );
@@ -105,12 +108,53 @@
QColor titlecolor = params->XTitleColor;
p->setPen( titlecolor );
p->setFont( params->xTitleFont() );
- p->drawText( imagewidth/2 - \
params->xtitle.length()*params->xTitleFontWidth()/2, + p->drawText( \
(imagewidth/2 - params->xtitle.length()*params->xTitleFontWidth()/2) + \
params->legend_wth,
imageheight-params->xTitleFontHeight()-1, params->xtitle );
}
}
+void KChartEngine::drawLegendAndColors()
+{
+ if( !params->legend.isEmpty() ) {
+ int i, j;
+ for ( i = 0, j = params->labelFontHeight(); i < num_points_rows; i++, \
j=j+params->labelFontHeight()) { + QString y_legend;
+ QColor labelcolor = params->ExtColor.color(i);
+ p->setPen( labelcolor );
+ p->setFont( params->labelFont() );
+ int LineNumber;
+ int LineNumberCount;
+ int NumberOfMaximumCharacter;
+ int m, n;
+ LineNumber = params->legend[i].length() / 17 + 1;
+ LineNumberCount = 1;
+ n = 0;
+ if ( LineNumber > 1 ) {
+ do {
+ QString y_legend_sort;
+ if ( 16*LineNumberCount > params->legend[i].length() )
+ NumberOfMaximumCharacter = params->legend[i].length();
+ else
+ NumberOfMaximumCharacter = 16 * LineNumberCount;
+
+ for ( m = n; m < NumberOfMaximumCharacter; m++ )
+ y_legend_sort += params->legend[i][m];
+
+ p->drawText( 5, j, y_legend_sort );
+ LineNumberCount++;
+ if ( LineNumberCount < LineNumber+1 )
+ j = j + params->labelFontHeight();
+ n = n + 16;
+ } while ( LineNumberCount < LineNumber+1 );
+ }
+ else {
+ y_legend = params->legend[i];
+ p->drawText( 5, j, y_legend );
+ }
+ }
+ }
+}
void KChartEngine::drawThumbnails() {
#ifdef THUMB_VALS
diff -ur koffice.org/kchart/kchartEngine_ComputeSize.cc \
koffice/kchart/kchartEngine_ComputeSize.cc
--- koffice.org/kchart/kchartEngine_ComputeSize.cc Tue Jan 9 20:45:17 2001
+++ koffice/kchart/kchartEngine_ComputeSize.cc Tue Jan 9 21:39:26 2001
@@ -29,6 +29,7 @@
int vtitle_hgt = params->do_vol() && !params->ytitle2.isEmpty()? \
1+params->yTitleFontHeight()+1: 0; int ylabel_wth = 0;
int vlabel_wth = 0;
+ int legend_wth = 0;
int xtics = params->grid||params->xaxis? 1+2: 0;
int ytics = params->grid||params->yaxis? 1+3: 0;
@@ -200,6 +201,18 @@
}
}
+ int legend_biggest = -MAXINT;
+ unsigned int legend_len = 0;
+ for( int i=0; i<num_points_rows; ++i ) {
+ legend_biggest = QMAX( legend_len, params->legend[i].length() );
+ legend_len=legend_biggest;
+ }
+ if (legend_biggest > 16)
+ legend_biggest = 16;
+
+ legend_wth = 1+ legend_biggest*params->labelFontWidth() +1;
+ params->legend_wth = legend_wth;
+
graphwidth = imagewidth - ( ( (params->hard_size && params->hard_xorig)? \
params->hard_xorig:
( ytitle_hgt +
ylabel_wth +
@@ -207,6 +220,7 @@
+ vtics
+ vtitle_hgt
+ vlabel_wth
+ + legend_wth
+ xdepth_3Dtotal );
if( params->hard_size && params->hard_graphwidth ) /* \
user wants to use his */ graphwidth = params->hard_graphwidth;
diff -ur koffice.org/kchart/kchartEngine_Grids.cc \
koffice/kchart/kchartEngine_Grids.cc
--- koffice.org/kchart/kchartEngine_Grids.cc Tue Jan 9 20:45:17 2001
+++ koffice/kchart/kchartEngine_Grids.cc Tue Jan 9 21:39:26 2001
@@ -322,6 +322,9 @@
void KChartEngine::drawYAxisTitle() {
if( params->yaxis && !params->ytitle.isEmpty() )
{
+ if (params->isPie())
+ params->legend_wth = 0;
+
int ytit_len = params->ytitle.length()*params->yTitleFontWidth();
/*QColor titlecolor = params->YTitleColor==Qt::black?
PlotColor: params->YTitleColor;*/
@@ -331,7 +334,7 @@
p->rotate(-90);
//p->drawText( 0, imageheight/2 + ytit_len/2, params->ytitle );
p->drawText(- imageheight/2 -ytit_len/2,
- params->yTitleFontHeight(),params->ytitle);
+ params->yTitleFontHeight() + \
params->legend_wth,params->ytitle);
p->rotate(90);
}
diff -ur koffice.org/kchart/kchartparams.h koffice/kchart/kchartparams.h
--- koffice.org/kchart/kchartparams.h Tue Jan 9 20:45:17 2001
+++ koffice/kchart/kchartparams.h Tue Jan 9 21:39:26 2001
@@ -198,6 +198,7 @@
int hard_graphwidth;
int hard_xorig;
int hard_yorig;
+ int legend_wth;
// background pixmap stuff
KPixmap backgroundPixmap;
["koffice-kchart-bug4-20010109.diff" (text/plain)]
diff -ur koffice.org/kchart/kchartEngine2.cc koffice/kchart/kchartEngine2.cc
--- koffice.org/kchart/kchartEngine2.cc Tue Jan 9 20:45:17 2001
+++ koffice/kchart/kchartEngine2.cc Tue Jan 9 20:47:39 2001
@@ -97,7 +97,7 @@
kdDebug(35001) << "done with the title text" << endl;
- if( !params->xtitle.isEmpty() )
+ if( !params->xtitle.isEmpty() && !params->isPie() )
{
//QColor titlecolor = params->XTitleColor == Qt::black ?
// PlotColor: params->XTitleColor;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic