[Kst] kdeextragear-2/kst/kst

Andrew Walker arwalker at sumusltd.com
Thu Dec 9 23:20:03 CET 2004


CVS commit by arwalker: 

Better calculate the tick positions. Previously RelPlotRegion.width()/height() was used to determine the scale. This is incorrect as if the height is, for example, 100 then we want to scale by one less than this. If we draw to rows 0 and 100 then this will actually exceed the RelPlotRegion by one pixel, as RelPlotRegion is confined from pixels 0 to 99.


  M +16 -14    kst2dplot.cpp   1.306


--- kdeextragear-2/kst/kst/kst2dplot.cpp  #1.305:1.306
@@ -2041,8 +2041,8 @@ void Kst2DPlot::draw(QPainter &p, KstPai
   QRect RelWinRegion(0, 0, d2i(x_px), d2i(y_px));
 
-  x_orig_px = (tpx.org - x_min) / (x_max - x_min) * double(RelPlotRegion.width()) + xleft_bdr_px;
-  y_orig_px = (y_max - tpy.org) / (y_max - y_min) * double(RelPlotRegion.height()) + ytop_bdr_px;
-  xtick_px = (tpx.tick / (x_max - x_min)) * double(RelPlotRegion.width());
-  ytick_px = (tpy.tick / (y_max - y_min)) * double(RelPlotRegion.height());
+  x_orig_px = (tpx.org - x_min) / (x_max - x_min) * double(RelPlotRegion.width()-1) + xleft_bdr_px;
+  y_orig_px = (y_max - tpy.org) / (y_max - y_min) * double(RelPlotRegion.height()-1) + ytop_bdr_px;
+  xtick_px = (tpx.tick / (x_max - x_min)) * double(RelPlotRegion.width()-1);
+  ytick_px = (tpy.tick / (y_max - y_min)) * double(RelPlotRegion.height()-1);
 
   if (type != P_PRINT && type != P_EXPORT) {
@@ -2059,6 +2059,6 @@ void Kst2DPlot::draw(QPainter &p, KstPai
     Ly = RelPlotRegion.top();
     Hy = RelPlotRegion.bottom();
-    m_X =  double(RelPlotRegion.width())/(x_max - x_min);
-    m_Y = -double(RelPlotRegion.height())/(y_max - y_min);
+    m_X =  double(RelPlotRegion.width()-1)/(x_max - x_min);
+    m_Y = -double(RelPlotRegion.height()-1)/(y_max - y_min);
     b_X = Lx - m_X * x_min;
     b_Y = Ly - m_Y * y_max;
@@ -2086,6 +2086,6 @@ void Kst2DPlot::draw(QPainter &p, KstPai
     if (!Legend->getFront()) {
       Legend->draw(&Curves, p,
-          d2i(xleft_bdr_px + RelPlotRegion.width() * Legend->x()),
-          d2i(ytop_bdr_px + RelPlotRegion.height() * Legend->y()));
+          d2i(xleft_bdr_px + double(RelPlotRegion.width()) * Legend->x()),
+          d2i(ytop_bdr_px + double(RelPlotRegion.height()) * Legend->y()));
     }
 
@@ -2105,6 +2105,6 @@ void Kst2DPlot::draw(QPainter &p, KstPai
     if (Legend->getFront()) {
       Legend->draw(&Curves, p,
-          d2i(xleft_bdr_px + RelPlotRegion.width() * Legend->x()),
-          d2i(ytop_bdr_px + RelPlotRegion.height() * Legend->y()));
+          d2i(xleft_bdr_px + double(RelPlotRegion.width()) * Legend->x()),
+          d2i(ytop_bdr_px + double(RelPlotRegion.height()) * Legend->y()));
     }
 
@@ -2113,6 +2113,6 @@ void Kst2DPlot::draw(QPainter &p, KstPai
     //
     for (KstLabel *label = _labelList.first(); label; label = _labelList.next()) {
-      label->draw(p, d2i(xleft_bdr_px + RelPlotRegion.width() * label->x()),
-                  d2i(ytop_bdr_px + RelPlotRegion.height() * label->y()));
+      label->draw(p, d2i(xleft_bdr_px + double(RelPlotRegion.width()) * label->x()),
+                  d2i(ytop_bdr_px + double(RelPlotRegion.height()) * label->y()));
     }
 
@@ -5608,5 +5608,5 @@ void Kst2DPlot::plotAxes(QPainter& p, QR
 
   //
-  // draw X Ticks
+  // draw x-ticks
   //
   if (_xLog) {
@@ -5628,4 +5628,5 @@ void Kst2DPlot::plotAxes(QPainter& p, QR
                    d2i(y_px - ybot_bdr_px - 2.0 * xtick_len_px));
       }
+      
       //
       // draw minor ticks
@@ -5675,5 +5676,5 @@ void Kst2DPlot::plotAxes(QPainter& p, QR
 
   //
-  // draw Y Ticks
+  // draw y ticks
   //
   if (_yLog) {
@@ -5694,4 +5695,5 @@ void Kst2DPlot::plotAxes(QPainter& p, QR
                    d2i(Y1));
       }
+      
       //
       // draw minor ticks





More information about the Kst mailing list