Summary: | bar graph bars widths are not correctly calculated for unevenly spaced data | ||
---|---|---|---|
Product: | [Applications] kst | Reporter: | Brendan Crill <bpc> |
Component: | general | Assignee: | kst |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | NOR | ||
Version: | 1.x | ||
Target Milestone: | --- | ||
Platform: | unspecified | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: |
Description
Brendan Crill
2006-03-16 01:25:53 UTC
Clearly what is being done is incorrect, but what is the correct thing to do? There seem to be at least a couple of options: 1) Make each bar a fixed width, with the width being the smallest difference between data points 2) Make the bars variable width Brendan, what were you expecting in your case? Hi Andrew, I think option 1 would be fine for a default. A nice feature would be to have control over the width. Barth's idea (he happens to be sitting right next to me) is if the X error bar option is set, have that vector set the bar width. Thanks! Fixed for monotonically increasing x-axis 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); } |