[Kst] [Bug 123698] bar graph bars widths are not correctly calculated for unevenly spaced data
Andrew Walker
arwalker at sumusltd.com
Fri Mar 17 21:14:45 CET 2006
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
http://bugs.kde.org/show_bug.cgi?id=123698
------- Additional Comments From arwalker sumusltd com 2006-03-17 21:14 -------
SVN commit 519650 by arwalker:
CCBUG:123698 Make bar width the smallest difference between data points on the x-axis in the case where x-data is monotonically increasing. The x-error bar, if set, already defines the bar width.
M +26 -8 kstvcurve.cpp
--- trunk/extragear/graphics/kst/src/libkstmath/kstvcurve.cpp #519649:519650
@ -843,7 +843,7 @
bool _xLog = context._xLog, _yLog = context._yLog;
int penWidth = context.penWidth;
double maxY = 0.0, minY = 0.0;
- double rX, rY, rEX, rEY;
+ double rX = 0.0, rY, rEX, rEY;
double X1 = 0.0, Y1 = 0.0;
double X2 = 0.0, Y2 = 0.0;
double last_x1, last_y1;
@ -1145,10 +1145,12 @
// we might have some overlapping points still unplotted...
if (overlap) {
if (X2 >= Lx && X2 <= Hx) {
- if (maxY > Hy && minY <= Hy)
+ if (maxY > Hy && minY <= Hy) {
maxY = Hy;
- if (minY < Ly && maxY >= Ly)
+ }
+ if (minY < Ly && maxY >= Ly) {
minY = Ly;
+ }
if (minY >= Ly && minY <= Hy && maxY >= Ly && maxY <= Hy) {
p->drawLine(d2i(X2), d2i(minY), d2i(X2), d2i(maxY));
}
@ -1174,7 +1176,7 @
bool has_right = true;
bool visible = true;
double rX2 = 0.0;
- double drX;
+ double drX = 0.0;
if (barStyle() == 1) { // filled
p->setPen(QPen(_foregroundColor, width, style));
@ -1182,13 +1184,29 @
p->setPen(QPen(color(), width, style));
}
- drX = (maxX() - minX())/double(sampleCount());
+ if (!exv) {
+ // determine the bar position width. NOTE: This is done
+ // only if xv->isRising() as in this case the calculation
+ // is simple...
+ drX = (maxX() - minX())/double(sampleCount());
+ if (xv->isRising()) {
+ double oldX = 0.0;
+
+ for (i_pt = i0; i_pt <= iN; i_pt++) {
+ rX = xv->interpolate(i_pt, NS);
+ if (i_pt > i0) {
+ if (rX - oldX < drX) {
+ drX = rX - oldX;
+ }
+ }
+ oldX = rX;
+ }
+ }
+ }
+
for (i_pt = i0; i_pt <= iN; i_pt++) {
visible = has_bot = has_top = has_left = has_right = true;
- // determine the bar position width.
- // NOTE: this assumes even X spacing if XError is not defined
- // There may a better way...
if (exv) {
drX = exv->interpolate(i_pt, NS);
}
More information about the Kst
mailing list