Class: Clowk::Phlex::Charts::GaugeRadial
- Inherits:
-
Clowk::Phlex::Component
- Object
- Phlex::HTML
- Clowk::Phlex::Component
- Clowk::Phlex::Charts::GaugeRadial
- Defined in:
- lib/clowk/phlex/charts/gauge_radial.rb
Overview
Components::UI::GaugeRadial — semicircle "fuel gauge" for a capacity / percent metric (ported from voodu Metrics::GaugeRadial). The arc fills with the current %, the number sits big in the center and an absolute value (e.g. "13.2 / 42 GB") below it. The fill tints AMBER past 70% and RED past 90% so a resource nearing its ceiling jumps out. Pure server SVG (no JS).
percent: true → center reads the fill "%".
percent: false → center reads value_label (raw count) instead.
Constant Summary collapse
- R =
arc radius
76- CX =
center x
100- CY =
baseline y the arc springs up from
96- SW =
arc stroke width
16
Instance Method Summary collapse
-
#initialize(pct:, color: "#5B8DEF", sub_label: nil, max_w: 220, percent: true, value_label: nil) ⇒ GaugeRadial
constructor
A new instance of GaugeRadial.
- #view_template ⇒ Object
Constructor Details
#initialize(pct:, color: "#5B8DEF", sub_label: nil, max_w: 220, percent: true, value_label: nil) ⇒ GaugeRadial
Returns a new instance of GaugeRadial.
17 18 19 20 21 22 23 24 |
# File 'lib/clowk/phlex/charts/gauge_radial.rb', line 17 def initialize(pct:, color: "#5B8DEF", sub_label: nil, max_w: 220, percent: true, value_label: nil) @pct = clamp(pct.to_f) @color = color @sub_label = sub_label @max_w = max_w @percent = percent @value_label = value_label.to_s end |
Instance Method Details
#view_template ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/clowk/phlex/charts/gauge_radial.rb', line 26 def view_template arc = Math::PI * R fill = (@pct / 100.0) * arc svg( viewBox: "0 0 200 116", class: "block mx-auto w-full h-auto", style: "max-width: #{@max_w}px;", fill: "none", role: "img", "aria-label": "#{@pct.round}%" ) do |s| s.path(d: arc_path, stroke: "var(--clowk-surface-3)", "stroke-width": SW, "stroke-linecap": "round") s.path( d: arc_path, stroke: fill_color, "stroke-width": SW, "stroke-linecap": "round", "stroke-dasharray": "#{fill.round(2)} #{arc.round(2)}" ) s.text( x: CX, y: CY - 6, "text-anchor": "middle", fill: "var(--clowk-text)", "font-size": "30", "font-weight": "600", "font-family": "var(--clowk-font-sans, system-ui, sans-serif)" ) { center_label } if @sub_label.present? s.text( x: CX, y: CY + 13, "text-anchor": "middle", fill: "var(--clowk-muted)", "font-size": "12", "font-family": "var(--clowk-font-mono, ui-monospace, monospace)" ) { @sub_label } end end end |