Class: HakumiComponents::Progress::CircleGeometry

Inherits:
Object
  • Object
show all
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

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

#dashoffsetObject



44
45
46
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 44

def dashoffset
  gap_length / 2.0
end

#effective_lengthObject



34
35
36
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 34

def effective_length
  total_length - gap_length
end

#gap_lengthObject



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

#radiusObject



19
20
21
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 19

def radius
  50 - (@stroke_width / 2.0)
end

#rotationObject



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_lengthObject



24
25
26
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 24

def total_length
  2 * Math::PI * radius
end

#transformObject



54
55
56
# File 'app/components/hakumi_components/progress/circle_geometry.rb', line 54

def transform
  "rotate(#{rotation} 50 50)"
end