pub struct VoronoiChart { /* private fields */ }Expand description
Voronoi diagram widget.
Cells are drawn at half-block resolution (two rows of dots per terminal row) in a screen-uniform space, so edges are the true perpendicular bisectors as they appear on screen.
§Example
use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
use tui_chart::{Gradient, VoronoiChart, VoronoiSite};
let chart = VoronoiChart::new([
VoronoiSite::new("a", 1.0, 1.0).value(3.0),
VoronoiSite::new("b", 5.0, 3.0).value(9.0),
VoronoiSite::new("c", 3.0, 6.0).value(5.0),
])
.gradient(Gradient::Viridis)
.show_labels(true);
let area = Rect::new(0, 0, 40, 14);
let mut buf = Buffer::empty(area);
chart.render(area, &mut buf);Implementations§
Source§impl VoronoiChart
impl VoronoiChart
Sourcepub fn new(sites: impl IntoIterator<Item = VoronoiSite>) -> Self
pub fn new(sites: impl IntoIterator<Item = VoronoiSite>) -> Self
Create a diagram from sites; sites with non-finite coordinates are skipped.
Sourcepub fn metric(self, v: VoronoiMetric) -> Self
pub fn metric(self, v: VoronoiMetric) -> Self
Distance metric (default Euclidean).
Sourcepub fn weighted(self, v: bool) -> Self
pub fn weighted(self, v: bool) -> Self
Weighted (power) diagram: heavier sites own larger cells (default off).
Sourcepub fn farthest(self, v: bool) -> Self
pub fn farthest(self, v: bool) -> Self
Farthest-site diagram: each point takes its farthest site (default off).
Sourcepub fn show_sites(self, v: bool) -> Self
pub fn show_sites(self, v: bool) -> Self
Mark each site with ● (default on).
Sourcepub fn show_labels(self, v: bool) -> Self
pub fn show_labels(self, v: bool) -> Self
Print the site label next to its marker (default off).
Sourcepub fn fill_dim(self, v: f64) -> Self
pub fn fill_dim(self, v: f64) -> Self
How much cell fills are darkened toward black, 0.0..=1.0 (default 0.45).
Sourcepub fn border_color(self, v: Color) -> Self
pub fn border_color(self, v: Color) -> Self
Edge color (default: a light tint of the cell color).
Sourcepub fn gradient(self, v: Gradient) -> Self
pub fn gradient(self, v: Gradient) -> Self
Color cells by VoronoiSite::value through this gradient.
Sourcepub fn merge_categories(self, v: bool) -> Self
pub fn merge_categories(self, v: bool) -> Self
Merge borders between same-category cells (default on).
Sourcepub fn knn(self, v: usize) -> Self
pub fn knn(self, v: usize) -> Self
k-nearest-neighbour classifier: each point takes the majority
category of its k nearest sites (default 1 = plain Voronoi).
Sourcepub fn shade_by_distance(self, v: bool) -> Self
pub fn shade_by_distance(self, v: bool) -> Self
Brightness follows the distance to the nearest site: glowing
centres, dark edges (default off; replaces fill_dim).
Sourcepub fn relax(self, v: usize) -> Self
pub fn relax(self, v: usize) -> Self
Lloyd relaxation steps: sites move to their cell centroids, giving an even, honeycomb-like (centroidal) diagram (default 0).
Sourcepub fn delaunay(self, v: bool) -> Self
pub fn delaunay(self, v: bool) -> Self
Overlay the Delaunay graph: a line between every pair of neighbouring sites (default off).
Sourcepub fn phase(self, v: f64) -> Self
pub fn phase(self, v: f64) -> Self
Animation phase; sites drift around their position (default 0).
Sourcepub fn probe(self, v: (f64, f64)) -> Self
pub fn probe(self, v: (f64, f64)) -> Self
Insert a temporary extra site at data position (x, y), e.g. the
mouse cursor, to show which part of the plot it would steal.
Sourcepub fn select(self, v: usize) -> Self
pub fn select(self, v: usize) -> Self
Highlight the cell of site index i and outline its neighbours.
Sourcepub fn axes(self, v: bool) -> Self
pub fn axes(self, v: bool) -> Self
Draw x/y axes with tick labels, like a scatter plot (default off).
Sourcepub fn bounds(self, x0: f64, x1: f64, y0: f64, y1: f64) -> Self
pub fn bounds(self, x0: f64, x1: f64, y0: f64, y1: f64) -> Self
Fix the visible data window instead of fitting it to the sites.
Sourcepub fn square(self, v: bool) -> Self
pub fn square(self, v: bool) -> Self
Equal x/y scale (no stretching), e.g. for maps (default off).
Sourcepub fn clip_circle(self, v: bool) -> Self
pub fn clip_circle(self, v: bool) -> Self
Paint only the inscribed disc (default off).
Sourcepub fn base_style(self, style: Style) -> Self
pub fn base_style(self, style: Style) -> Self
Base style painted over the whole area (beats the theme).
Trait Implementations§
Source§impl Clone for VoronoiChart
impl Clone for VoronoiChart
Source§impl Debug for VoronoiChart
impl Debug for VoronoiChart
Source§impl Default for VoronoiChart
impl Default for VoronoiChart
Source§impl Themed for VoronoiChart
Available on crate feature theme only.
impl Themed for VoronoiChart
theme only.Source§fn apply_theme(self, theme: &Theme) -> Self
fn apply_theme(self, theme: &Theme) -> Self
self styled from theme. Explicit per-item colors set on the
widget should keep winning over the theme.Source§fn themed(self, provider: &impl ThemeProvider) -> Self
fn themed(self, provider: &impl ThemeProvider) -> Self
ThemeProvider.Source§impl Widget for &VoronoiChart
impl Widget for &VoronoiChart
Auto Trait Implementations§
impl Forget for VoronoiChart
impl Freeze for VoronoiChart
impl Move for VoronoiChart
impl RefUnwindSafe for VoronoiChart
impl Send for VoronoiChart
impl Sync for VoronoiChart
impl Unpin for VoronoiChart
impl UnsafeUnpin for VoronoiChart
impl UnwindSafe for VoronoiChart
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more