Class: HeatmapBuilder::Calendar
- Inherits:
-
Object
- Object
- HeatmapBuilder::Calendar
- Includes:
- SvgHelpers, ValueConversion
- Defined in:
- lib/heatmap_builder/calendar.rb
Constant Summary collapse
- GITHUB_GREEN =
%w[#ebedf0 #9be9a8 #40c463 #30a14e #216e39].freeze
- BLUE_OCEAN =
%w[#f0f9ff #bae6fd #7dd3fc #38bdf8 #0ea5e9].freeze
- WARM_SUNSET =
%w[#fef3e2 #fed7aa #fdba74 #fb923c #f97316].freeze
- PURPLE_VIBES =
%w[#f3e8ff #d8b4fe #c084fc #a855f7 #9333ea].freeze
- RED_TO_GREEN =
%w[#f5f5f5 #ff9999 #f7ad6a #d2c768 #99dd99].freeze
- DEFAULT_OPTIONS =
{ cell_size: 12, cell_spacing: 1, font_size: 8, border_width: 1, border_lightness_factor: 0.9, corner_radius: 0, colors: GITHUB_GREEN, start_of_week: :monday, month_spacing: 0, show_month_labels: true, show_day_labels: true, show_outside_cells: false, day_labels: %w[S M T W T F S], month_labels: %w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec], tooltip: nil, tooltip_attribute: "data-tooltip" }.freeze
- VALID_START_DAYS =
%i[sunday monday tuesday wednesday thursday friday saturday].freeze
- LABEL_COLOR =
"#666666"- FONT_VERTICAL_CENTER_RATIO =
0.35- MONTH_LABEL_Y_RATIO =
1.25- MONTH_LABEL_HEIGHT_RATIO =
1.625- MONTH_LABEL_INDENT_RATIO =
0.1- WEEK_START_WDAY =
{ sunday: 0, monday: 1, tuesday: 2, wednesday: 3, thursday: 4, friday: 5, saturday: 6 }.freeze
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(scores: nil, values: nil, **options) ⇒ Calendar
constructor
A new instance of Calendar.
Constructor Details
#initialize(scores: nil, values: nil, **options) ⇒ Calendar
Returns a new instance of Calendar.
54 55 56 57 58 59 60 |
# File 'lib/heatmap_builder/calendar.rb', line 54 def initialize(scores: nil, values: nil, **) @scores = scores @values = values @options = DEFAULT_OPTIONS.merge() end |
Instance Method Details
#build ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/heatmap_builder/calendar.rb', line 62 def build svg_content = [] if [:show_day_labels] svg_content << day_labels_svg end svg_content << calendar_cells_svg if [:show_month_labels] svg_content << month_labels_svg end cell_size_with_spacing = [:cell_size] + [:cell_spacing] width = dow_label_offset + total_column_count * cell_size_with_spacing + total_month_spacing height = month_label_offset + 7 * cell_size_with_spacing svg_container(width: width, height: height) { svg_content.join } end |