Sha256: fd601293669ce4659a888f3bf180e95e46606b4bd27a5533db8b4b5edc915a37

Contents?: true

Size: 1.61 KB

Versions: 60

Compression:

Stored size: 1.61 KB

Contents

module EventCalendar
  module CalendarHelper
    private

    # calculate the height of each row
    # by default, it will be the height option minus the day names height,
    # divided by the total number of calendar rows
    # this gets tricky, however, if there are too many event rows to fit into the row's height
    # then we need to add additional height
    def cal_row_heights(options)
      # number of rows is the number of days in the event strips divided by 7
      num_cal_rows = (options[:event_strips].first.size / 7).to_i
      # the row will be at least this big
      min_height = ((options[:height] - options[:day_names_height]) / num_cal_rows).to_i
      row_heights = []
      num_event_rows = 0
      # for every day in the event strip...
      1.upto(options[:event_strips].first.size+1) do |index|
        num_events = 0
        # get the largest event strip that has an event on this day
        options[:event_strips].each_with_index do |strip, strip_num|
          num_events = strip_num + 1 unless strip[index-1].blank?
        end
        # get the most event rows for this week
        num_event_rows = [num_event_rows, num_events].max
        # if we reached the end of the week, calculate this row's height
        if index % 7 == 0
          total_event_height = options[:event_height] + options[:event_margin]
          calc_row_height = (num_event_rows * total_event_height) + options[:day_nums_height] + options[:event_margin]
          row_height = [min_height, calc_row_height].max
          row_heights << row_height
          num_event_rows = 0
        end
      end
      row_heights
    end
  end
end

Version data entries

60 entries across 60 versions & 2 rubygems

Version Path
enju_biblio-0.1.0.pre42 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre41 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_flower-0.1.0.pre9 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre40 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre39 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_flower-0.1.0.pre8 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre38 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_flower-0.1.0.pre7 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre37 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_flower-0.1.0.pre6 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre36 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre35 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre34 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_flower-0.1.0.pre5 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre33 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre32 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_flower-0.1.0.pre4 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre31 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre30 spec/dummy/lib/plugins/ext/event-calendar.rb
enju_biblio-0.1.0.pre29 spec/dummy/lib/plugins/ext/event-calendar.rb