Ticket #22 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

yvals above bars

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

Description

I'm new to python and I'm not very familiar with pycha yet, so I'm not sure what the best way to do this is. My "hack" is to add:

######### render yvals above bars ###########

cx.save() cx.set_source_rgba(0, 0, 0, 1) label = unicode(bar.yval) extents = cx.text_extents(label) labelWidth = extents[2] labelHeight = extents[3] cx.move_to(x+(w/2.0)-labelWidth, y-labelHeight) cx.show_text(label) cx.restore()

after the bar proportions have been gathered in the drawBar method in bar.py (line 75). I set y tickCount to 0 in my options because I'm not sure how to handle overlapping.

There should obviously be an option for this. Maybe "showYvals". Other options might include placement ("over bar" or "inside bar"). I set my maxyval to be 30% more than my maximum yval to avoid drawing over the whole graph for the maximum bar.

Attachments

yvals_above_bars.patch (1.3 kB) - added by aprzywecki@… 3 years ago.
add option for showing y values over bars (VerticalBarChart? only)
yvals-above-bars.diff (2.1 kB) - added by aprzywecki@… 3 years ago.
show yvals above/beside bars (with option to put values inside bars)

Change History

Changed 3 years ago by aprzywecki@…

Sorry about the code. Second try:

######### render numbers above bars ###########
            cx.save()
            cx.set_source_rgba(0, 0, 0, 1)
            label = unicode(bar.yval)
            extents = cx.text_extents(label)
            labelWidth = extents[2]
            labelHeight = extents[3]
            cx.move_to(x+(w/2.0)-labelWidth, y-labelHeight)
            cx.show_text(label)
            cx.restore()

Changed 3 years ago by aprzywecki@…

Patch for yvals over bars is attached. It's disabled by default. Please use:

'showyvals': {'hide': False}

The other option is 'showyvals': {'fontSize': XX}.

This ONLY works for VerticalBarChart?. As far as I can see, the drawBar method does not know (or care) if it's drawing horizontal or vertical bars. However, this information is required to draw the y values properly (my patch assumes that it's always a vertical chart).

Should VerticalBarChart? and HorizontalBarChart? set a flag so that we can draw the values properly? Lorenzo, what do you think?

Adam

Changed 3 years ago by aprzywecki@…

add option for showing y values over bars (VerticalBarChart? only)

Changed 3 years ago by aprzywecki@…

Attached is a patch that works for both horizontal and vertical bars. There is also an option for putting the values inside bars.
Options:
showyvals=Option(

hide=True,
fontSize=11,
insideBar=False
)


Please test yvals-above-bars.diff

Changed 3 years ago by aprzywecki@…

show yvals above/beside bars (with option to put values inside bars)

Changed 3 years ago by lgs

I have commited a modified version of your patch in changeset [149]. Some comments about it:

  • I've changed the name of the option because it was not intuitive when you wanted to show the yvals. E.g. you need to set showyvals: {'hide': False} in your options. Now the option is called yvals and you just show them or hide them (default value).
  • I've updated chavier. Remember that every time you add/remove/change an option you need to update chavier.
  • In case the text does not fit inside the bar I decided to draw it above/right to the bar.
  • I have added a color option for the yval label because if you want to draw it inside the bar you will probably want it to be other than black.
  • I have renamed the option insideBar to just inside because in the future we may want to do the same with LineCharts

Changed 3 years ago by anonymous

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.