diff --git a/crates/story/src/chart_story.rs b/crates/story/src/chart_story.rs index a5d6ff25..33338f93 100644 --- a/crates/story/src/chart_story.rs +++ b/crates/story/src/chart_story.rs @@ -164,7 +164,7 @@ impl Render for ChartStory { .child(chart_container( "Pie Chart", PieChart::new(self.monthly_devices.clone()) - .value(|d| d.desktop) + .value(|d| d.desktop as f32) .outer_radius(100.) .color(move |d| d.color(color)), true, @@ -173,7 +173,7 @@ impl Render for ChartStory { .child(chart_container( "Pie Chart - Donut", PieChart::new(self.monthly_devices.clone()) - .value(|d| d.desktop) + .value(|d| d.desktop as f32) .outer_radius(100.) .inner_radius(60.) .color(move |d| d.color(color)), @@ -183,7 +183,7 @@ impl Render for ChartStory { .child(chart_container( "Pie Chart - Pad Angle", PieChart::new(self.monthly_devices.clone()) - .value(|d| d.desktop) + .value(|d| d.desktop as f32) .outer_radius(100.) .inner_radius(60.) .pad_angle(4. / 100.) diff --git a/crates/ui/src/chart/area_chart.rs b/crates/ui/src/chart/area_chart.rs index 0bf7fd28..7ab82e35 100644 --- a/crates/ui/src/chart/area_chart.rs +++ b/crates/ui/src/chart/area_chart.rs @@ -94,8 +94,8 @@ where return; } - let width = bounds.size.width.to_f64(); - let height = bounds.size.height.to_f64() - AXIS_GAP; + let width = bounds.size.width.0; + let height = bounds.size.height.0 - AXIS_GAP; // X scale let x = ScalePoint::new(self.data.iter().map(|v| x_fn(v)).collect(), vec![0., width]); @@ -134,7 +134,7 @@ where // Draw grid Grid::new() - .y((0..=3).map(|i| height * i as f64 / 4.0).collect()) + .y((0..=3).map(|i| height * i as f32 / 4.0).collect()) .stroke(cx.theme().border) .dash_array(&[px(4.), px(2.)]) .paint(&bounds, window); diff --git a/crates/ui/src/chart/bar_chart.rs b/crates/ui/src/chart/bar_chart.rs index b6504b30..6de7ab28 100644 --- a/crates/ui/src/chart/bar_chart.rs +++ b/crates/ui/src/chart/bar_chart.rs @@ -90,8 +90,8 @@ where return; }; - let width = bounds.size.width.to_f64(); - let height = bounds.size.height.to_f64() - AXIS_GAP; + let width = bounds.size.width.0; + let height = bounds.size.height.0 - AXIS_GAP; // X scale let x = ScaleBand::new(self.data.iter().map(|v| x_fn(v)).collect(), vec![0., width]) @@ -133,7 +133,7 @@ where // Draw grid Grid::new() - .y((0..=3).map(|i| height * i as f64 / 4.0).collect()) + .y((0..=3).map(|i| height * i as f32 / 4.0).collect()) .stroke(cx.theme().border) .dash_array(&[px(4.), px(2.)]) .paint(&bounds, window); diff --git a/crates/ui/src/chart/line_chart.rs b/crates/ui/src/chart/line_chart.rs index 40650041..96f589a6 100644 --- a/crates/ui/src/chart/line_chart.rs +++ b/crates/ui/src/chart/line_chart.rs @@ -85,8 +85,8 @@ where return; }; - let width = bounds.size.width.to_f64(); - let height = bounds.size.height.to_f64() - AXIS_GAP; + let width = bounds.size.width.0; + let height = bounds.size.height.0 - AXIS_GAP; // X scale let x = ScalePoint::new(self.data.iter().map(|v| x_fn(v)).collect(), vec![0., width]); @@ -126,7 +126,7 @@ where // Draw grid Grid::new() - .y((0..=3).map(|i| height * i as f64 / 4.0).collect()) + .y((0..=3).map(|i| height * i as f32 / 4.0).collect()) .stroke(cx.theme().border) .dash_array(&[px(4.), px(2.)]) .paint(&bounds, window); diff --git a/crates/ui/src/chart/pie_chart.rs b/crates/ui/src/chart/pie_chart.rs index b74decb3..aa4ef258 100644 --- a/crates/ui/src/chart/pie_chart.rs +++ b/crates/ui/src/chart/pie_chart.rs @@ -15,10 +15,10 @@ use crate::{ #[derive(IntoPlot)] pub struct PieChart { data: Vec, - inner_radius: f64, - outer_radius: f64, - pad_angle: f64, - value: Option f64>>, + inner_radius: f32, + outer_radius: f32, + pad_angle: f32, + value: Option f32>>, color: Option Hsla>>, } @@ -37,22 +37,22 @@ impl PieChart { } } - pub fn inner_radius(mut self, inner_radius: f64) -> Self { + pub fn inner_radius(mut self, inner_radius: f32) -> Self { self.inner_radius = inner_radius; self } - pub fn outer_radius(mut self, outer_radius: f64) -> Self { + pub fn outer_radius(mut self, outer_radius: f32) -> Self { self.outer_radius = outer_radius; self } - pub fn pad_angle(mut self, pad_angle: f64) -> Self { + pub fn pad_angle(mut self, pad_angle: f32) -> Self { self.pad_angle = pad_angle; self } - pub fn value(mut self, value: impl Fn(&T) -> f64 + 'static) -> Self { + pub fn value(mut self, value: impl Fn(&T) -> f32 + 'static) -> Self { self.value = Some(Rc::new(value)); self } @@ -73,7 +73,7 @@ impl Plot for PieChart { }; let outer_radius = if self.outer_radius.is_zero() { - bounds.size.height.to_f64() * 0.4 + bounds.size.height.0 * 0.4 } else { self.outer_radius }; diff --git a/crates/ui/src/plot/axis.rs b/crates/ui/src/plot/axis.rs index 89bc657c..76fb4330 100644 --- a/crates/ui/src/plot/axis.rs +++ b/crates/ui/src/plot/axis.rs @@ -5,7 +5,7 @@ use gpui::{ use super::{label::Label, label::Text, label::TEXT_GAP, label::TEXT_SIZE, origin_point}; -pub const AXIS_GAP: f64 = 18.; +pub const AXIS_GAP: f32 = 18.; pub struct AxisText { pub text: SharedString, @@ -75,7 +75,7 @@ impl Axis { .into_iter() .map(|t| Text { text: t.text, - origin: point(t.tick, x + px((TEXT_GAP * 3.) as f32)), + origin: point(t.tick, x + px(TEXT_GAP * 3.)), color: t.color, font_size: t.font_size, font_weight: FontWeight::NORMAL, @@ -105,7 +105,7 @@ impl Axis { .into_iter() .map(|t| Text { text: t.text, - origin: point(y + px(TEXT_GAP as f32), t.tick), + origin: point(y + px(TEXT_GAP), t.tick), color: t.color, font_size: t.font_size, font_weight: FontWeight::NORMAL, diff --git a/crates/ui/src/plot/label.rs b/crates/ui/src/plot/label.rs index 418452f6..25fae840 100644 --- a/crates/ui/src/plot/label.rs +++ b/crates/ui/src/plot/label.rs @@ -7,9 +7,9 @@ use gpui::{ use super::origin_point; -pub const TEXT_SIZE: f64 = 10.; -pub const TEXT_GAP: f64 = 2.; -pub const TEXT_HEIGHT: f64 = TEXT_SIZE + TEXT_GAP; +pub const TEXT_SIZE: f32 = 10.; +pub const TEXT_GAP: f32 = 2.; +pub const TEXT_HEIGHT: f32 = TEXT_SIZE + TEXT_GAP; pub struct Text { pub text: SharedString, diff --git a/crates/ui/src/plot/mod.rs b/crates/ui/src/plot/mod.rs index 4c3aab25..d360151a 100644 --- a/crates/ui/src/plot/mod.rs +++ b/crates/ui/src/plot/mod.rs @@ -35,15 +35,15 @@ where pub fn polygon(points: &[Point], bounds: &Bounds) -> Option> where - T: Default + Clone + Copy + Debug + Into + PartialEq, + T: Default + Clone + Copy + Debug + Into + PartialEq, { let mut path = PathBuilder::stroke(px(1.)); let points = &points .iter() .map(|p| { point( - px((p.x.into() + bounds.origin.x.to_f64()) as f32), - px((p.y.into() + bounds.origin.y.to_f64()) as f32), + px(p.x.into() + bounds.origin.x.0), + px(p.y.into() + bounds.origin.y.0), ) }) .collect::>(); diff --git a/crates/ui/src/plot/scale.rs b/crates/ui/src/plot/scale.rs index 2b219fe3..dfd0ecff 100644 --- a/crates/ui/src/plot/scale.rs +++ b/crates/ui/src/plot/scale.rs @@ -10,8 +10,8 @@ pub(crate) use sealed::Sealed; pub trait Scale { /// Get the tick of the scale. - fn tick(&self, value: &T) -> Option; + fn tick(&self, value: &T) -> Option; /// Get the least index of the scale. - fn least_index(&self, tick: f64) -> usize; + fn least_index(&self, tick: f32) -> usize; } diff --git a/crates/ui/src/plot/scale/band.rs b/crates/ui/src/plot/scale/band.rs index 6b7cb1e9..f9d54950 100644 --- a/crates/ui/src/plot/scale/band.rs +++ b/crates/ui/src/plot/scale/band.rs @@ -8,15 +8,15 @@ use super::Scale; #[derive(Clone)] pub struct ScaleBand { domain: Vec, - range_diff: f64, - avg_width: f64, - padding_inner: f64, - padding_outer: f64, + range_diff: f32, + avg_width: f32, + padding_inner: f32, + padding_outer: f32, } impl ScaleBand { - pub fn new(domain: Vec, range: Vec) -> Self { - let len = domain.len() as f64; + pub fn new(domain: Vec, range: Vec) -> Self { + let len = domain.len() as f32; let range_diff = range .iter() .minmax() @@ -33,18 +33,18 @@ impl ScaleBand { } /// Get the width of the band. - pub fn band_width(&self) -> f64 { + pub fn band_width(&self) -> f32 { (self.avg_width * (1. - self.padding_inner)).min(30.) } /// Set the padding inner of the band. - pub fn padding_inner(mut self, padding_inner: f64) -> Self { + pub fn padding_inner(mut self, padding_inner: f32) -> Self { self.padding_inner = padding_inner; self } /// Set the padding outer of the band. - pub fn padding_outer(mut self, padding_outer: f64) -> Self { + pub fn padding_outer(mut self, padding_outer: f32) -> Self { self.padding_outer = padding_outer; self } @@ -54,7 +54,7 @@ impl Scale for ScaleBand where T: PartialEq, { - fn tick(&self, value: &T) -> Option { + fn tick(&self, value: &T) -> Option { let index = self.domain.iter().position(|v| v == value)?; let domain_len = self.domain.len(); @@ -63,13 +63,13 @@ where return Some((self.range_diff - self.band_width()) / 2.); } - let ratio = 1. + self.padding_inner / (self.domain.len() - 1) as f64; + let ratio = 1. + self.padding_inner / (self.domain.len() - 1) as f32; let padding_outer_width = self.avg_width * self.padding_outer; - let avg_width = (self.range_diff - padding_outer_width * 2.) / self.domain.len() as f64; - Some(index as f64 * avg_width * ratio + padding_outer_width) + let avg_width = (self.range_diff - padding_outer_width * 2.) / self.domain.len() as f32; + Some(index as f32 * avg_width * ratio + padding_outer_width) } - fn least_index(&self, tick: f64) -> usize { + fn least_index(&self, tick: f32) -> usize { let index = (tick / self.avg_width).round() as usize; index.min(self.domain.len().saturating_sub(1)) } diff --git a/crates/ui/src/plot/scale/linear.rs b/crates/ui/src/plot/scale/linear.rs index 767dce5b..2d085f4c 100644 --- a/crates/ui/src/plot/scale/linear.rs +++ b/crates/ui/src/plot/scale/linear.rs @@ -10,15 +10,15 @@ pub struct ScaleLinear { domain_len: usize, domain_min: T, domain_diff: T, - range_min: f64, - range_diff: f64, + range_min: f32, + range_diff: f32, } impl ScaleLinear where T: Copy + PartialOrd + Num + ToPrimitive + Sealed, { - pub fn new(domain: Vec, range: Vec) -> Self { + pub fn new(domain: Vec, range: Vec) -> Self { let (domain_min, domain_max) = domain .iter() .minmax() @@ -45,17 +45,17 @@ impl Scale for ScaleLinear where T: Copy + PartialOrd + Num + ToPrimitive + Sealed, { - fn tick(&self, value: &T) -> Option { + fn tick(&self, value: &T) -> Option { if self.domain_diff.is_zero() { return None; } - let ratio = ((*value - self.domain_min) / self.domain_diff).to_f64()?; + let ratio = ((*value - self.domain_min) / self.domain_diff).to_f32()?; Some((1. - ratio) * self.range_diff + self.range_min) } - fn least_index(&self, tick: f64) -> usize { + fn least_index(&self, tick: f32) -> usize { let index = (tick / self.range_diff).round() as usize; index.min(self.domain_len.saturating_sub(1)) } diff --git a/crates/ui/src/plot/scale/point.rs b/crates/ui/src/plot/scale/point.rs index f34a5dcb..9080217f 100644 --- a/crates/ui/src/plot/scale/point.rs +++ b/crates/ui/src/plot/scale/point.rs @@ -8,14 +8,14 @@ use super::Scale; #[derive(Clone)] pub struct ScalePoint { domain: Vec, - range_tick: f64, + range_tick: f32, } impl ScalePoint where T: PartialEq, { - pub fn new(domain: Vec, range: Vec) -> Self { + pub fn new(domain: Vec, range: Vec) -> Self { let len = domain.len(); let range_tick = if len.is_zero() { 0. @@ -26,7 +26,7 @@ where .into_option() .map_or(0., |(min, max)| max - min); - range_diff / (len - 1) as f64 + range_diff / (len - 1) as f32 }; Self { domain, range_tick } @@ -37,12 +37,12 @@ impl Scale for ScalePoint where T: PartialEq, { - fn tick(&self, value: &T) -> Option { + fn tick(&self, value: &T) -> Option { let index = self.domain.iter().position(|v| v == value)?; - Some(index as f64 * self.range_tick) + Some(index as f32 * self.range_tick) } - fn least_index(&self, tick: f64) -> usize { + fn least_index(&self, tick: f32) -> usize { let index = (tick / self.range_tick).round() as usize; index.min(self.domain.len().saturating_sub(1)) } diff --git a/crates/ui/src/plot/shape/arc.rs b/crates/ui/src/plot/shape/arc.rs index b4b70c98..31238eb6 100644 --- a/crates/ui/src/plot/shape/arc.rs +++ b/crates/ui/src/plot/shape/arc.rs @@ -1,19 +1,19 @@ // @reference: https://d3js.org/d3-shape/arc -use std::{f64::consts::PI, fmt::Debug}; +use std::{f32::consts::PI, fmt::Debug}; use gpui::{point, px, Bounds, Hsla, Path, PathBuilder, Pixels, Point, Window}; -const EPSILON: f64 = 1e-12; -const HALF_PI: f64 = PI / 2.; +const EPSILON: f32 = 1e-12; +const HALF_PI: f32 = PI / 2.; pub struct ArcData<'a, T> { pub data: &'a T, pub index: usize, - pub value: f64, - pub start_angle: f64, - pub end_angle: f64, - pub pad_angle: f64, + pub value: f32, + pub start_angle: f32, + pub end_angle: f32, + pub pad_angle: f32, } impl Debug for ArcData<'_, T> { @@ -27,8 +27,8 @@ impl Debug for ArcData<'_, T> { } pub struct Arc { - inner_radius: f64, - outer_radius: f64, + inner_radius: f32, + outer_radius: f32, } impl Default for Arc { @@ -46,19 +46,19 @@ impl Arc { } /// Set the inner radius of the Arc. - pub fn inner_radius(mut self, inner_radius: f64) -> Self { + pub fn inner_radius(mut self, inner_radius: f32) -> Self { self.inner_radius = inner_radius; self } /// Set the outer radius of the Arc. - pub fn outer_radius(mut self, outer_radius: f64) -> Self { + pub fn outer_radius(mut self, outer_radius: f32) -> Self { self.outer_radius = outer_radius; self } /// Get the centroid of the Arc. - pub fn centroid(&self, arc: &ArcData) -> Point { + pub fn centroid(&self, arc: &ArcData) -> Point { let start_angle = arc.start_angle - HALF_PI; let end_angle = arc.end_angle - HALF_PI; let r = (self.inner_radius + self.outer_radius) / 2.; @@ -75,8 +75,8 @@ impl Arc { let r1 = self.outer_radius.max(0.); // Calculate the center point. - let center_x = bounds.origin.x.to_f64() + bounds.size.width.to_f64() / 2.; - let center_y = bounds.origin.y.to_f64() + bounds.size.height.to_f64() / 2.; + let center_x = bounds.origin.x.0 + bounds.size.width.0 / 2.; + let center_y = bounds.origin.y.0 + bounds.size.height.0 / 2.; // Angle difference. let da = end_angle - start_angle; @@ -123,38 +123,38 @@ impl Arc { let mut builder = PathBuilder::fill(); // Move to the start point of the outer arc. - builder.move_to(point(px(x01 as f32), px(y01 as f32))); + builder.move_to(point(px(x01), px(y01))); // Draw the outer arc. let large_arc = (a1_outer - a0_outer).abs() > PI; builder.arc_to( - point(px(r1 as f32), px(r1 as f32)), + point(px(r1), px(r1)), px(0.), large_arc, true, - point(px(x11 as f32), px(y11 as f32)), + point(px(x11), px(y11)), ); if r0 > EPSILON { // End point of the inner arc. let x10 = center_x + r0 * a1_inner.cos(); let y10 = center_y + r0 * a1_inner.sin(); - builder.line_to(point(px(x10 as f32), px(y10 as f32))); + builder.line_to(point(px(x10), px(y10))); // Draw the inner arc. let x00 = center_x + r0 * a0_inner.cos(); let y00 = center_y + r0 * a0_inner.sin(); let large_arc_inner = (a1_inner - a0_inner).abs() > PI; builder.arc_to( - point(px(r0 as f32), px(r0 as f32)), + point(px(r0), px(r0)), px(0.), large_arc_inner, false, - point(px(x00 as f32), px(y00 as f32)), + point(px(x00), px(y00)), ); } else { // If there is no inner radius, draw a line to the center. - builder.line_to(point(px(center_x as f32), px(center_y as f32))); + builder.line_to(point(px(center_x), px(center_y))); } builder.build().ok() diff --git a/crates/ui/src/plot/shape/area.rs b/crates/ui/src/plot/shape/area.rs index 966188a3..a86b31a1 100644 --- a/crates/ui/src/plot/shape/area.rs +++ b/crates/ui/src/plot/shape/area.rs @@ -7,9 +7,9 @@ use crate::plot::{origin_point, StrokeStyle}; #[allow(clippy::type_complexity)] pub struct Area { data: Vec, - x: Box Option>, - y0: Option, - y1: Box Option>, + x: Box Option>, + y0: Option, + y1: Box Option>, fill: Background, stroke: Background, stroke_style: StrokeStyle, @@ -46,14 +46,14 @@ impl Area { /// Set the x of the Area. pub fn x(mut self, x: F) -> Self where - F: Fn(&T) -> Option + 'static, + F: Fn(&T) -> Option + 'static, { self.x = Box::new(x); self } /// Set the y0 of the Area. - pub fn y0(mut self, y0: f64) -> Self { + pub fn y0(mut self, y0: f32) -> Self { self.y0 = Some(y0); self } @@ -61,7 +61,7 @@ impl Area { /// Set the y1 of the Area. pub fn y1(mut self, y1: F) -> Self where - F: Fn(&T) -> Option + 'static, + F: Fn(&T) -> Option + 'static, { self.y1 = Box::new(y1); self @@ -97,7 +97,7 @@ impl Area { let y_tick = (self.y1)(v); if let (Some(x), Some(y)) = (x_tick, y_tick) { - let pos = origin_point(px(x as f32), px(y as f32), origin); + let pos = origin_point(px(x), px(y), origin); points.push(pos); } @@ -150,8 +150,8 @@ impl Area { if let Some(last) = self.data.last() { let x_tick = (self.x)(last); if let (Some(x), Some(y)) = (x_tick, self.y0) { - area_builder.line_to(origin_point(px(x as f32), px(y as f32), bounds.origin)); - area_builder.line_to(origin_point(px(0.), px(y as f32), bounds.origin)); + area_builder.line_to(origin_point(px(x), px(y), bounds.origin)); + area_builder.line_to(origin_point(px(0.), px(y), bounds.origin)); area_builder.close(); } } diff --git a/crates/ui/src/plot/shape/bar.rs b/crates/ui/src/plot/shape/bar.rs index 6e7def92..5371fac5 100644 --- a/crates/ui/src/plot/shape/bar.rs +++ b/crates/ui/src/plot/shape/bar.rs @@ -8,10 +8,10 @@ use crate::plot::{ #[allow(clippy::type_complexity)] pub struct Bar { data: Vec, - x: Box Option>, - band_width: f64, - y0: f64, - y1: Box Option>, + x: Box Option>, + band_width: f32, + y0: f32, + y1: Box Option>, fill: Box Hsla>, label: Option) -> Text>>, } @@ -47,20 +47,20 @@ impl Bar { /// Set the x of the Bar. pub fn x(mut self, x: F) -> Self where - F: Fn(&T) -> Option + 'static, + F: Fn(&T) -> Option + 'static, { self.x = Box::new(x); self } /// Set the band width of the Bar. - pub fn band_width(mut self, band_width: f64) -> Self { + pub fn band_width(mut self, band_width: f32) -> Self { self.band_width = band_width; self } /// Set the y0 of the Bar. - pub fn y0(mut self, y0: f64) -> Self { + pub fn y0(mut self, y0: f32) -> Self { self.y0 = y0; self } @@ -68,7 +68,7 @@ impl Bar { /// Set the y1 of the Bar. pub fn y1(mut self, y: F) -> Self where - F: Fn(&T) -> Option + 'static, + F: Fn(&T) -> Option + 'static, { self.y1 = Box::new(y); self @@ -106,21 +106,13 @@ impl Bar { let is_negative = y_tick > self.y0; let (p1, p2) = if is_negative { ( - origin_point(px(x_tick as f32), px(self.y0 as f32), origin), - origin_point( - px((x_tick + self.band_width) as f32), - px(y_tick as f32), - origin, - ), + origin_point(px(x_tick), px(self.y0), origin), + origin_point(px(x_tick + self.band_width), px(y_tick), origin), ) } else { ( - origin_point(px(x_tick as f32), px(y_tick as f32), origin), - origin_point( - px((x_tick + self.band_width) as f32), - px(self.y0 as f32), - origin, - ), + origin_point(px(x_tick), px(y_tick), origin), + origin_point(px(x_tick + self.band_width), px(self.y0), origin), ) }; @@ -132,11 +124,11 @@ impl Bar { labels.push(label( v, point( - px((x_tick + self.band_width / 2.) as f32), + px(x_tick + self.band_width / 2.), if is_negative { - px((y_tick + TEXT_GAP) as f32) + px(y_tick + TEXT_GAP) } else { - px((y_tick - TEXT_HEIGHT) as f32) + px(y_tick - TEXT_HEIGHT) }, ), )); diff --git a/crates/ui/src/plot/shape/line.rs b/crates/ui/src/plot/shape/line.rs index a258208f..9bb8caac 100644 --- a/crates/ui/src/plot/shape/line.rs +++ b/crates/ui/src/plot/shape/line.rs @@ -10,8 +10,8 @@ use crate::plot::{origin_point, StrokeStyle}; #[allow(clippy::type_complexity)] pub struct Line { data: Vec, - x: Box Option>, - y: Box Option>, + x: Box Option>, + y: Box Option>, stroke: Background, stroke_width: Pixels, stroke_style: StrokeStyle, @@ -55,7 +55,7 @@ impl Line { /// Set the x of the Line. pub fn x(mut self, x: F) -> Self where - F: Fn(&T) -> Option + 'static, + F: Fn(&T) -> Option + 'static, { self.x = Box::new(x); self @@ -64,7 +64,7 @@ impl Line { /// Set the y of the Line. pub fn y(mut self, y: F) -> Self where - F: Fn(&T) -> Option + 'static, + F: Fn(&T) -> Option + 'static, { self.y = Box::new(y); self @@ -135,15 +135,11 @@ impl Line { let y_tick = (self.y)(v); if let (Some(x), Some(y)) = (x_tick, y_tick) { - let pos = origin_point(px(x as f32), px(y as f32), origin); + let pos = origin_point(px(x), px(y), origin); if self.dot { - let dot_radius = self.dot_size.to_f64() / 2.; - let dot_pos = origin_point( - px((x - dot_radius) as f32), - px((y - dot_radius) as f32), - origin, - ); + let dot_radius = self.dot_size.0 / 2.; + let dot_pos = origin_point(px(x - dot_radius), px(y - dot_radius), origin); paint_dots.push(self.paint_dot(dot_pos)); } diff --git a/crates/ui/src/plot/shape/pie.rs b/crates/ui/src/plot/shape/pie.rs index 11bf5b38..54e08f04 100644 --- a/crates/ui/src/plot/shape/pie.rs +++ b/crates/ui/src/plot/shape/pie.rs @@ -1,15 +1,15 @@ // @reference: https://d3js.org/d3-shape/pie -use std::f64::consts::TAU; +use std::f32::consts::TAU; use super::arc::ArcData; #[allow(clippy::type_complexity)] pub struct Pie { - value: Box Option>, - start_angle: f64, - end_angle: f64, - pad_angle: f64, + value: Box Option>, + start_angle: f32, + end_angle: f32, + pad_angle: f32, } impl Default for Pie { @@ -31,26 +31,26 @@ impl Pie { /// Set the value of the Pie. pub fn value(mut self, value: F) -> Self where - F: 'static + Fn(&T) -> Option, + F: 'static + Fn(&T) -> Option, { self.value = Box::new(value); self } /// Set the start angle of the Pie. - pub fn start_angle(mut self, start_angle: f64) -> Self { + pub fn start_angle(mut self, start_angle: f32) -> Self { self.start_angle = start_angle; self } /// Set the end angle of the Pie. - pub fn end_angle(mut self, end_angle: f64) -> Self { + pub fn end_angle(mut self, end_angle: f32) -> Self { self.end_angle = end_angle; self } /// Set the pad angle of the Pie. - pub fn pad_angle(mut self, pad_angle: f64) -> Self { + pub fn pad_angle(mut self, pad_angle: f32) -> Self { self.pad_angle = pad_angle; self } diff --git a/crates/ui/src/plot/tooltip.rs b/crates/ui/src/plot/tooltip.rs index cc82fe4a..45dd7f4a 100644 --- a/crates/ui/src/plot/tooltip.rs +++ b/crates/ui/src/plot/tooltip.rs @@ -19,8 +19,8 @@ impl CrossLine { } } - pub fn height(mut self, height: f64) -> Self { - self.height = Some(height as f32); + pub fn height(mut self, height: f32) -> Self { + self.height = Some(height); self } }