Class: HakumiComponents::Progress::CircleGeometry
- Inherits:
-
Object
- Object
- HakumiComponents::Progress::CircleGeometry
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/progress/circle_geometry.rb
Constant Summary collapse
- ProgressValue =
T.type_alias { Numeric }
Instance Method Summary collapse
- #dasharray(length) ⇒ Object
- #dashoffset ⇒ Object
- #effective_length ⇒ Object
- #gap_length ⇒ Object
-
#initialize(stroke_width:, gap_degree:, gap_position:) ⇒ CircleGeometry
constructor
A new instance of CircleGeometry.
- #path_length(percent) ⇒ Object
- #radius ⇒ Object
- #rotation ⇒ Object
- #total_length ⇒ Object
- #transform ⇒ Object
Constructor Details
#initialize(stroke_width:, gap_degree:, gap_position:) ⇒ CircleGeometry
Returns a new instance of CircleGeometry.
12 13 14 15 16 |
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 12 def initialize(stroke_width:, gap_degree:, gap_position:) @stroke_width = T.let(stroke_width, Float) @gap_degree = T.let(gap_degree, Float) @gap_position = T.let(gap_position, Symbol) end |
Instance Method Details
#dasharray(length) ⇒ Object
49 50 51 |
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 49 def dasharray(length) "#{format_float(length)} #{format_float(total_length)}" end |
#dashoffset ⇒ Object
44 45 46 |
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 44 def dashoffset gap_length / 2.0 end |
#effective_length ⇒ Object
34 35 36 |
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 34 def effective_length total_length - gap_length end |
#gap_length ⇒ Object
29 30 31 |
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 29 def gap_length total_length * (@gap_degree / 360.0) end |
#path_length(percent) ⇒ Object
39 40 41 |
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 39 def path_length(percent) effective_length * (percent.to_f / 100.0) end |
#radius ⇒ Object
19 20 21 |
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 19 def radius 50 - (@stroke_width / 2.0) end |
#rotation ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 59 def rotation case @gap_position when :left then 180 when :right then 0 when :bottom then 90 else -90 end end |
#total_length ⇒ Object
24 25 26 |
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 24 def total_length 2 * Math::PI * radius end |
#transform ⇒ Object
54 55 56 |
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 54 def transform "rotate(#{rotation} 50 50)" end |