pub struct Chart<K: Kind> { /* private fields */ }Expand description
A D3 chart. Render it in a Maud template.
use autumn_plugin_d3::{Chart, Format};
let chart = Chart::bar([("Apples", 3.0), ("Pears", 5.0)])
.label("Fruit sold")
.y_label("Units")
.format(Format::integer());
let html = autumn_web::html! { (chart) }.into_string();
assert!(html.contains(r#"data-d3="bar""#), "{html}");
assert!(html.contains("<table"), "fallback table: {html}");Implementations§
Source§impl<K: Kind> Chart<K>
impl<K: Kind> Chart<K>
Sourcepub fn class(self, class: impl Into<String>) -> Self
pub fn class(self, class: impl Into<String>) -> Self
Adds CSS classes to the figure, after d3-chart.
Sourcepub fn label(self, label: impl Into<String>) -> Self
pub fn label(self, label: impl Into<String>) -> Self
Sets the accessible name of the chart. It is also the table caption.
Without it, the runtime uses the caption text.
Sourcepub fn x_label(self, label: impl Into<String>) -> Self
pub fn x_label(self, label: impl Into<String>) -> Self
Sets the x title (bottom axis) and the first table header.
Sourcepub fn y_label(self, label: impl Into<String>) -> Self
pub fn y_label(self, label: impl Into<String>) -> Self
Sets the value title (value axis) and the value table header.
Sourcepub fn colors(self, colors: impl IntoIterator<Item = Color>) -> Self
pub fn colors(self, colors: impl IntoIterator<Item = Color>) -> Self
Sets the series colors, in order. They replace the palette. At most 16 colors are used.
Sourcepub fn aspect(self, ratio: f64) -> Self
pub fn aspect(self, ratio: f64) -> Self
Sets the plot width / height ratio. The value is clamped to
0.2..=10. The default is 16 / 9 (from d3.css).
Sourcepub fn duration(self, duration: Duration) -> Self
pub fn duration(self, duration: Duration) -> Self
Sets the transition time. Zero turns transitions off. At most 10 s.
Sourcepub fn animate_reduced_motion(self) -> Self
pub fn animate_reduced_motion(self) -> Self
Animates also for users who ask for reduced motion.
Sourcepub fn src(self, url: impl Into<String>) -> Self
pub fn src(self, url: impl Into<String>) -> Self
Loads the data from a same-origin JSON URL. The JSON has the same shape as the inline data. Inline data, if any, shows first.
Source§impl<K: Xy> Chart<K>
impl<K: Xy> Chart<K>
Sourcepub fn x_scale(self, scale: Scale) -> Self
pub fn x_scale(self, scale: Scale) -> Self
Sets the x scale type. With Scale::Time, x is Unix milliseconds.
Sourcepub fn y_scale(self, scale: Scale) -> Self
pub fn y_scale(self, scale: Scale) -> Self
Sets the y scale type. Scale::Time is not a y scale; it means
Scale::Linear.
Source§impl Chart<Bar>
impl Chart<Bar>
Sourcepub fn bar<D: Into<Datum>>(data: impl IntoIterator<Item = D>) -> Self
pub fn bar<D: Into<Datum>>(data: impl IntoIterator<Item = D>) -> Self
Makes a bar chart. Repeated labels draw as separate bars.
Sourcepub fn horizontal(self) -> Self
pub fn horizontal(self) -> Self
Draws horizontal bars.
Source§impl Chart<Line>
impl Chart<Line>
Sourcepub fn line(series: impl IntoIterator<Item = Series>) -> Self
pub fn line(series: impl IntoIterator<Item = Series>) -> Self
Makes a line chart.
Source§impl Chart<Area>
impl Chart<Area>
Sourcepub fn area(series: impl IntoIterator<Item = Series>) -> Self
pub fn area(series: impl IntoIterator<Item = Series>) -> Self
Makes an area chart. Each series fills down to zero (or to the lower end of the value axis).
Source§impl Chart<Custom>
impl Chart<Custom>
Sourcepub fn custom(name: impl Into<String>) -> Result<Self, Error>
pub fn custom(name: impl Into<String>) -> Result<Self, Error>
Makes a custom chart. name is the kind name that
AutumnD3.register uses in JavaScript.
§Errors
Error::InvalidKind when name is not 1–64 characters of a-z,
0-9, and -, starting with a letter, or when it is a built-in
kind name.
use autumn_plugin_d3::Chart;
let chart = Chart::custom("network").unwrap().json(&[1, 2, 3]).unwrap();
assert_eq!(chart.data_json().as_deref(), Some("[1,2,3]"));
assert!(Chart::custom("Bad Name").is_err());Trait Implementations§
impl<K: PartialEq + Kind> StructuralPartialEq for Chart<K>
Auto Trait Implementations§
impl<K> Forget for Chart<K>
impl<K> Freeze for Chart<K>where
PhantomData<K>: Freeze,
impl<K> RefUnwindSafe for Chart<K>where
PhantomData<K>: RefUnwindSafe,
impl<K> Send for Chart<K>where
PhantomData<K>: Send,
impl<K> Sync for Chart<K>where
PhantomData<K>: Sync,
impl<K> Unpin for Chart<K>where
PhantomData<K>: Unpin,
impl<K> UnsafeUnpin for Chart<K>where
PhantomData<K>: UnsafeUnpin,
impl<K> UnwindSafe for Chart<K>where
PhantomData<K>: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Scoped for T
impl<T> Scoped for T
Source§fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
ScopeQuery for this type. Resolves the
registered scope at .load() time, not here.