hellogauges/gauges/
arc.rs1use yew::prelude::*;
19
20use super::svgdraw;
21
22#[derive(Clone, PartialEq)]
23pub struct ArcContext {
24 pub min: f64,
25 pub max: f64,
26 pub startangle: f64,
27 pub endangle: f64,
28 pub centerx: i32,
29 pub centery: i32,
30 pub r: f64,
31 pub class: &'static str,
32}
33
34#[derive(Properties, PartialEq)]
35pub struct ArcProps {
36 pub start: f64,
37 pub end: f64,
38 #[prop_or(1.0)]
39 pub r: f64,
40 #[prop_or_default]
41 pub style: String,
42}
43
44#[function_component(Arc)]
45pub fn arc(props: &ArcProps) -> Html {
46 let ctx = use_context::<ArcContext>().expect("no ctx found");
47
48 let arctotal = ctx.endangle - ctx.startangle;
49 let arcstart = svgdraw::padvalue(ctx.min, ctx.max, arctotal, props.start) + ctx.startangle;
50 let arcend = svgdraw::padvalue(ctx.min, ctx.max, arctotal, props.end) + ctx.startangle;
51
52 html! {
53 <path
54 d={svgdraw::arcpath(
55 ctx.centerx,
56 ctx.centery,
57 ctx.r * props.r,
58 arcstart,
59 arcend,
60 arcend - arcstart > 180.0,
61 1)}
62 class={ctx.class}
63 style={props.style.clone()}
64 />}
65}