Skip to main content

VoronoiChart

Struct VoronoiChart 

Source
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

Source

pub fn new(sites: impl IntoIterator<Item = VoronoiSite>) -> Self

Create a diagram from sites; sites with non-finite coordinates are skipped.

Source

pub fn metric(self, v: VoronoiMetric) -> Self

Distance metric (default Euclidean).

Source

pub fn weighted(self, v: bool) -> Self

Weighted (power) diagram: heavier sites own larger cells (default off).

Source

pub fn farthest(self, v: bool) -> Self

Farthest-site diagram: each point takes its farthest site (default off).

Source

pub fn borders(self, v: bool) -> Self

Draw lines along cell edges (default on).

Source

pub fn show_sites(self, v: bool) -> Self

Mark each site with ● (default on).

Source

pub fn show_labels(self, v: bool) -> Self

Print the site label next to its marker (default off).

Source

pub fn fill_dim(self, v: f64) -> Self

How much cell fills are darkened toward black, 0.0..=1.0 (default 0.45).

Source

pub fn border_color(self, v: Color) -> Self

Edge color (default: a light tint of the cell color).

Source

pub fn gradient(self, v: Gradient) -> Self

Color cells by VoronoiSite::value through this gradient.

Source

pub fn merge_categories(self, v: bool) -> Self

Merge borders between same-category cells (default on).

Source

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).

Source

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).

Source

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).

Source

pub fn delaunay(self, v: bool) -> Self

Overlay the Delaunay graph: a line between every pair of neighbouring sites (default off).

Source

pub fn phase(self, v: f64) -> Self

Animation phase; sites drift around their position (default 0).

Source

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.

Source

pub fn select(self, v: usize) -> Self

Highlight the cell of site index i and outline its neighbours.

Source

pub fn axes(self, v: bool) -> Self

Draw x/y axes with tick labels, like a scatter plot (default off).

Source

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.

Source

pub fn square(self, v: bool) -> Self

Equal x/y scale (no stretching), e.g. for maps (default off).

Source

pub fn clip_circle(self, v: bool) -> Self

Paint only the inscribed disc (default off).

Source

pub fn theme(self, theme: impl Into<Theme>) -> Self

Apply a Theme; explicit site colors win.

Source

pub fn base_style(self, style: Style) -> Self

Base style painted over the whole area (beats the theme).

Source

pub fn block(self, b: Block<'static>) -> Self

Wrap the chart in a Block.

Trait Implementations§

Source§

impl Clone for VoronoiChart

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VoronoiChart

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VoronoiChart

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Themed for VoronoiChart

Available on crate feature theme only.
Source§

fn apply_theme(self, theme: &Theme) -> Self

Return 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

Apply the theme produced by any ThemeProvider.
Source§

impl Widget for &VoronoiChart

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.
Source§

impl Widget for VoronoiChart

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.