# Trident specification sheet arrows. # # These methods should never need to be called directly. # @private class USPSFlags::Helpers::SpecArrows class << self # Creates a vertical arrow for the trident spec sheet. # # This is used USPSFlags::Core.trident_spec, and should never need to be called directly. # @private def vertical(x, top, bottom, pointer_top = nil, pointer_bottom = nil, label: nil, label_offset: (USPSFlags::Config::BASE_FLY/120), label_offset_y: 0, label_align: "left", color: "#CCCCCC", stroke_width: (USPSFlags::Config::BASE_FLY/600), stroke_dash: "10, 10", font_size: (USPSFlags::Config::BASE_FLY/60), arrow_size: (USPSFlags::Config::BASE_FLY/120), fly: USPSFlags::Config::BASE_FLY, unit: nil) label, label_fraction = get_labels(bottom, top, fly, label: label) svg = "" svg << arrow_pointer(x, pointer_top, top, top, color, stroke_width, stroke_dash) unless pointer_top.nil? svg << arrow_pointer(x, pointer_bottom, bottom, bottom, color, stroke_width, stroke_dash) unless pointer_bottom.nil? svg << <<~SVG #{label} #{label_fraction} #{unit} SVG svg end # Creates a horizontal arrow for the trident spec sheet. # # This is used USPSFlags::Core.trident_spec, and should never need to be called directly. # @private def horizontal(y, left, right, pointer_left = nil, pointer_right = nil, label: nil, label_offset: (USPSFlags::Config::BASE_FLY/45), label_offset_x: 0, label_align: "middle", color: "#CCCCCC", stroke_width: (USPSFlags::Config::BASE_FLY/600), stroke_dash: "10, 10", font_size: (USPSFlags::Config::BASE_FLY/60), arrow_size: (USPSFlags::Config::BASE_FLY/120), fly: USPSFlags::Config::BASE_FLY, unit: nil) label, label_fraction = get_labels(right, left, fly, label: label) svg = "" svg << arrow_pointer(left, left, pointer_left, y, color, stroke_width, stroke_dash) unless pointer_left.nil? svg << arrow_pointer(right, right, y, pointer_right, color, stroke_width, stroke_dash) unless pointer_right.nil? svg << <<~SVG #{label} #{label_fraction} #{unit} SVG svg end private def arrow_pointer(x1, x2, y1, y2, color, stroke_width, stroke_dash) <<~SVG SVG end def get_labels(a, b, fly, label: nil) label = a - b if label.nil? label = label.to_i if label - label.to_i == 0 label = Rational(label) * fly / USPSFlags::Config::BASE_FLY if label == label.to_i label = label.to_i label_fraction = "" else label, label_fraction = label.to_simplified_a end [label, label_fraction] end end end