Ticket #20 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

range does not always work as expected

Reported by: aprzywecki@… Owned by: somebody
Priority: major Milestone: 0.5.0
Component: component1 Version:
Keywords: Cc:

Description

When I specify my own range for x as (0.0, 4.0) and I have 5 data points, I get 5 x ticks and 5 bars as expected.

With the same range, if I have 2 data points, I get 3 x ticks (taking up less than half the graph) and 3 bars (one over each x tick) as expected.

However, with the same range, if I have just one data point, I get one tick (taking up 1/5th of the graph as expected) but the one bar takes up most of the graph instead of being over the tick.

Please refer to the attached image. The range there is (0.0, 4.0) but the bar takes up most of the graph.

It is currently impossible to plot one bar with a range that is greater than (0.0, 0.0). No problem for 2 or more bars and oversized ranges.

Attachments

range.png (27.4 kB) - added by aprzywecki@… 3 years ago.
shows x range problem for 1 bar
range-fixed.png (29.8 kB) - added by aprzywecki@… 3 years ago.
range_fix.patch (1.2 kB) - added by aprzywecki@… 3 years ago.
fixes bar proportion for single bar with an xrange greater than 0

Change History

Changed 3 years ago by aprzywecki@…

shows x range problem for 1 bar

Changed 3 years ago by aprzywecki@…

I found the cause of this problem. In bar.py, _updateChart() contains:

if len(uniqx) == 1:

xdelta = 1.0 barWidth = 1.0 * self.options.barWidthFillFraction self.barWidthForSet = barWidth / len(stores) self.barMargin = (1.0 - self.options.barWidthFillFraction) / 2

else:

xdelta = min([abs(uniqx[j] - uniqx[j-1])

for j in range(1, len(uniqx))])

barWidth = xdelta * self.xscale * self.options.barWidthFillFraction self.barWidthForSet = barWidth / len(stores) self.barMargin = (xdelta * self.xscale

  • (1.0 - self.options.barWidthFillFraction) / 2)

If there is only one bar, you treat it differently because uniqx[j] - uniqx[j-1] would fail. However, uniqx is just a series of numbers with a difference of one (for example, [0, 1, 2], or [0, 1, 2, 3, 4, 5]) so xdelta will always be 1 (as far as I can tell). What is the pursose of this xdelta calculation if the result is always 1?

My bug occurs because the unique case (uniqx == 1) does not use self.xscale to calculate barWidth. My proposed fix is to use:

xdelta = 1 barWidth = xdelta * self.xscale * self.options.barWidthFillFraction self.barWidthForSet = barWidth / len(stores) self.barMargin = (xdelta * self.xscale

  • (1.0 - self.options.barWidthFillFraction) / 2)

for all values of uniqx. Everything seems to work as expected and it fixes my bug (see attachment).

Adam

Changed 3 years ago by aprzywecki@…

Changed 3 years ago by aprzywecki@…

The attached patch fixes the above problem. Is it safe to assume that xdelta is always 1?

Changed 3 years ago by aprzywecki@…

fixes bar proportion for single bar with an xrange greater than 0

Changed 3 years ago by anonymous

  • milestone set to 0.5.0

Changed 3 years ago by lgs

  • status changed from new to closed
  • resolution set to fixed

You can't expect xdelta to always be 1.0 because that assumes that the user provided datasets are all regular and clean, which is not always true.

Anyway, you were right in that the computation of the bar width should not be different in the special case of having just one point.

I commited a modified version of your patch (and a regression test) in [176] so everything should be fine now. Thanks!!

Note: See TracTickets for help on using tickets.