@@ -7,9 +7,10 @@ module Squid
77 class Plotter
88 attr_accessor :paddings
99 # @param [Prawn::Document] a PDF document to wrap in a Plotter instance.
10- def initialize ( pdf , bottom :)
10+ def initialize ( pdf , bottom :, col_max_width : 0 )
1111 @pdf = pdf
1212 @bottom = bottom
13+ @col_max_width = col_max_width || 0
1314 end
1415
1516 # Draws a bounding box of the given height, rendering the block inside it.
@@ -96,14 +97,23 @@ def lines(series, options = {})
9697 def stacks ( series , options = { } )
9798 items ( series , options . merge ( fill : true ) ) do |point , w , i , padding |
9899 x , y = point . index *w + padding + left , point . y + @bottom
99- @pdf . fill_rectangle [ x , y ] , w - 2 *padding , point . height
100+ w -= 2 * padding
101+ if @col_max_width > 0 && @col_max_width < w
102+ x += ( w - @col_max_width ) / 2
103+ w = @col_max_width
104+ end
105+ @pdf . fill_rectangle [ x , y ] , w , point . height
100106 end
101107 end
102108
103109 def columns ( series , options = { } )
104110 items ( series , options . merge ( fill : true , count : series . size ) ) do |point , w , i , padding |
105111 item_w = ( w - 2 * padding ) / series . size
106112 x , y = point . index *w + padding + left + i *item_w , point . y + @bottom
113+ if @col_max_width > 0 && @col_max_width < item_w
114+ x += ( item_w - @col_max_width ) / 2
115+ item_w = @col_max_width
116+ end
107117 @pdf . fill_rectangle [ x , y ] , item_w , point . height
108118 end
109119 end
0 commit comments