@@ -156,7 +156,7 @@ impl<'a> BarChart<'a> {
156
156
self
157
157
}
158
158
159
- /// set the direction ob the bars
159
+ /// Set the direction of the bars
160
160
pub fn direction ( mut self , direction : Direction ) -> BarChart < ' a > {
161
161
self . direction = direction;
162
162
self
@@ -228,33 +228,23 @@ impl<'a> BarChart<'a> {
228
228
} )
229
229
. collect ( ) ;
230
230
231
- // print all visible bars (without labels and values)
231
+ // print all visible bars
232
232
let mut bar_y = bars_area. top ( ) ;
233
233
for ( group_data, mut group) in groups. into_iter ( ) . zip ( self . data ) {
234
234
let bars = std:: mem:: take ( & mut group. bars ) ;
235
235
236
- let label_offset = bars. len ( ) as u16 * ( self . bar_width + self . bar_gap ) - self . bar_gap ;
237
- // if group_gap is zero, then there is no place to print the group label
238
- // check also if the group label is still inside the visible area
239
- if self . group_gap > 0 && bar_y < bars_area. bottom ( ) - label_offset {
240
- let label_rect = Rect {
241
- y : bar_y + label_offset,
242
- ..bars_area
243
- } ;
244
- group. render_label ( buf, label_rect, self . label_style ) ;
245
- }
246
-
247
236
for ( bar_length, bar) in group_data. into_iter ( ) . zip ( bars) {
248
237
let bar_style = self . bar_style . patch ( bar. style ) ;
249
238
250
239
for y in 0 ..self . bar_width {
240
+ let bar_y = bar_y + y;
251
241
for x in 0 ..bars_area. width {
252
242
let symbol = if x < bar_length {
253
243
self . bar_set . full
254
244
} else {
255
245
self . bar_set . empty
256
246
} ;
257
- buf. get_mut ( bars_area. left ( ) + x, bar_y + y )
247
+ buf. get_mut ( bars_area. left ( ) + x, bar_y)
258
248
. set_symbol ( symbol)
259
249
. set_style ( bar_style) ;
260
250
}
@@ -275,7 +265,17 @@ impl<'a> BarChart<'a> {
275
265
bar_y += self . bar_gap + self . bar_width ;
276
266
}
277
267
278
- bar_y += self . group_gap ;
268
+ // if group_gap is zero, then there is no place to print the group label
269
+ // check also if the group label is still inside the visible area
270
+ let label_y = bar_y - self . bar_gap ;
271
+ if self . group_gap > 0 && label_y < bars_area. bottom ( ) {
272
+ let label_rect = Rect {
273
+ y : label_y,
274
+ ..bars_area
275
+ } ;
276
+ group. render_label ( buf, label_rect, self . label_style ) ;
277
+ bar_y += self . group_gap ;
278
+ }
279
279
}
280
280
}
281
281
0 commit comments