#![allow(missing_docs)]
pub mod figure {
pub const WIDTH_IN: f64 = 6.4;
pub const HEIGHT_IN: f64 = 4.8;
pub const DPI: f64 = 150.0;
}
pub mod font {
pub const TITLE_PT: f32 = 12.0;
pub const LABEL_PT: f32 = 10.0;
pub const TICK_PT: f32 = 10.0;
}
pub mod legend {
pub const OUTSIDE_PAD_PT: f64 = 4.0;
pub const OUTSIDE_WIDTH_EM: f64 = 6.0;
}
pub mod hatch {
pub const SPACING_PX: f64 = 8.0;
pub const STROKE_WIDTH: f64 = 0.85;
pub const DOT_RADIUS: f64 = 1.1;
}
pub mod subplot {
pub const LEFT: f64 = 0.125;
pub const RIGHT: f64 = 0.9;
pub const BOTTOM: f64 = 0.11;
pub const TOP: f64 = 0.88;
pub const HSPACE: f64 = 0.2;
pub const WSPACE: f64 = 0.2;
pub const AXES_WIDTH: f64 = RIGHT - LEFT;
pub const AXES_HEIGHT: f64 = TOP - BOTTOM;
pub const TIGHT_PAD_PT: f64 = 10.8;
pub const TIGHT_PAD_BOTTOM_FACTOR: f64 = 0.5;
pub const TIGHT_PAD_TOP_FACTOR: f64 = 0.85;
pub const TIGHT_INTERIOR_PAD_FACTOR: f64 = 0.95;
pub const INTERIOR_PAD_PT: f64 = 2.5;
}
pub mod colorbar {
pub const AXES_X1: f64 = 0.745;
pub const RIGHT_GUTTER: f64 = 1.0 - AXES_X1;
pub const GUTTER_FRAC: f64 = 0.20;
pub const BAR_WIDTH_PT: f64 = 11.0;
pub const GAP_PT: f64 = 14.0;
pub fn linear_tick_targets(vmin: f64, vmax: f64) -> usize {
let span = (vmax - vmin).abs();
let intish = (vmin - vmin.round()).abs() < 1e-9 && (vmax - vmax.round()).abs() < 1e-9;
if span > 0.0 && intish && span <= 24.0 {
let step2_targets = (span / 2.0).round() as usize + 1;
step2_targets.clamp(5, 13)
} else if span > 0.0 && span <= 5.0 {
7
} else {
5
}
}
}
pub mod chrome {
pub const TITLE_GAP_PT: f64 = 6.0;
pub const TITLE_CELL_INSET_PT: f64 = 2.0;
pub const TITLE_TWIN_BASELINE_EM: f64 = 0.90;
pub const TITLE_TWIN_STACK_GAP_PT: f64 = 8.0;
pub const X_LABEL_GAP_PT: f64 = 14.0;
pub const X_LABEL_EDGE_PT: f64 = 15.0;
pub const Y_LABEL_INSET_PT: f64 = 17.0;
pub const Y_LABEL_INSET_TWIN_Y_PT: f64 = 15.0;
pub const Y_LABEL_INSET_RIGHT_PT: f64 = 11.0;
pub const TWIN_X_LABEL_GAP_PT: f64 = 12.5;
pub const TICK_LABEL_PAD_PT: f64 = 3.5;
pub const Y_LABEL_AIR_PT: f64 = 10.0;
pub const Y_LABEL_EDGE_PT: f64 = 2.0;
pub const Y_LABEL_FIGURE_FLOOR_PT: f64 = 9.0;
}
pub mod datetime {
pub const TICK_ROTATION_DEG: f64 = -30.0;
pub const ROTATED_BAND_EM: f64 = 0.9;
pub const AUTOFMT_BOTTOM: f64 = 0.20;
pub const X_LABEL_BAND_FRAC: f64 = 0.72;
}
pub mod polar {
pub const R_MARGIN: f64 = 1.026;
pub const RING_LEVEL_FACTOR: f64 = 1.02;
pub const RING_N_HINT: usize = 5;
pub const TITLE_CLEAR_PT: f64 = 28.0;
pub const ANGLE_LABEL_TOP_PT: f64 = 14.0;
#[inline]
pub fn rmax_from_data(data_rmax: f64) -> f64 {
data_rmax.abs().max(1e-9) * R_MARGIN
}
#[inline]
pub fn ring_level_span(data_rmax: f64) -> f64 {
data_rmax.abs().max(1e-9) * RING_LEVEL_FACTOR
}
}
pub mod scatter {
use std::f64::consts::PI;
pub const DEFAULT_DIAMETER_PT: f64 = 6.770_275_002_573_076;
#[inline]
pub fn diameter_from_area_pt2(s: f64) -> f64 {
2.0 * (s.max(0.0) / PI).sqrt()
}
}
pub mod quiver {
pub const WIDTH_PT: f64 = 1.4;
pub const HEAD_LENGTH_WIDTH: f64 = 5.0;
pub const HEAD_WIDTH_WIDTH: f64 = 3.0;
pub const SPAN_DIV: f64 = 18.0;
}
pub mod pie {
pub const VIEW: f64 = 1.25;
pub const RADIUS: f64 = 1.0;
pub const RADIUS_FRAC: f64 = RADIUS / (2.0 * VIEW);
pub const LABEL_DISTANCE: f64 = 1.1;
}
pub mod inset {
pub const CHROME_PAD_PT: f64 = 0.0;
}
pub mod annotate {
pub const MUTATION_SCALE_PT: f64 = 10.0;
pub const LINEWIDTH_PT: f64 = 1.0;
pub const SHRINK_PT: f64 = 2.0;
pub const TEXT_PAD_PT: f64 = 4.0;
pub const HEAD_LENGTH: f64 = 0.4;
pub const HEAD_WIDTH: f64 = 0.2;
pub const BRACKET_WIDTH: f64 = 1.0;
pub const BRACKET_LENGTH: f64 = 0.2;
}
pub mod barbs {
pub const STAFF_PT_SQUARE_SCALE: f64 = 0.5;
#[inline]
pub fn staff_length_px(length_pt: f64, px_per_pt: f64) -> f64 {
length_pt * length_pt * STAFF_PT_SQUARE_SCALE * px_per_pt
}
}
pub mod margin {
pub const PAD: f64 = 0.05;
}
pub mod violin {
pub const STEM_HALF_WIDTH_FRAC: f64 = 0.25;
pub const POINTS: usize = 100;
pub const WIDTHS: f64 = 0.5;
}
pub mod hexbin {
pub const POLYGON_SCALE: f64 = 1.0;
}
pub mod ticks {
pub const LINEAR_TARGETS: usize = 9;
pub const AUTO_NBINS_MAX: usize = 9;
pub const TICK_SPACE_ASPECT_X: f64 = 3.0;
pub const TICK_SPACE_ASPECT_Y: f64 = 2.0;
pub fn auto_nbins(axis_len_px: f64, dpi: f64, tick_label_size_pt: f64, is_x: bool) -> usize {
let length_pt = axis_len_px * 72.0 / dpi.max(1e-6);
let aspect = if is_x {
TICK_SPACE_ASPECT_X
} else {
TICK_SPACE_ASPECT_Y
};
let size = tick_label_size_pt * aspect;
let space = if size > 0.0 {
(length_pt / size).floor().max(0.0) as usize
} else {
AUTO_NBINS_MAX
};
space.clamp(1, AUTO_NBINS_MAX)
}
pub fn auto_targets(axis_len_px: f64, dpi: f64, tick_label_size_pt: f64, is_x: bool) -> usize {
auto_nbins(axis_len_px, dpi, tick_label_size_pt, is_x) + 1
}
}
pub mod axes3d {
use plotine_core::Color;
pub const ELEV: f64 = 30.0;
pub const AZIM: f64 = -60.0;
pub const BOX_ASPECT_RATIO: [f64; 3] = [4.0, 4.0, 3.0];
pub fn box_aspect() -> [f64; 3] {
let [ax, ay, az] = BOX_ASPECT_RATIO;
let norm = (ax * ax + ay * ay + az * az).sqrt();
let scale = 1.829_464_072_162_043_4 * (25.0 / 24.0) / norm;
[ax * scale, ay * scale, az * scale]
}
pub const DIST: f64 = 10.0;
pub const FOCAL_LENGTH: f64 = 1.0;
pub const BAR_FACE_SHADE: [f64; 6] = [0.5333, 0.7667, 0.8833, 0.4167, 0.8833, 0.4167];
pub const DEPTHSHADE_ALPHA_RANGE: f64 = 0.7;
pub const SCATTER_DIAMETER_PT: f64 = 4.513_519_491_406_296;
pub fn pane_face(axis: usize) -> Color {
match axis {
1 => Color::rgb(243, 243, 243), 2 => Color::rgb(245, 245, 245), _ => Color::rgb(248, 248, 248), }
}
pub fn grid_color() -> Color {
Color::rgb(0xb0, 0xb0, 0xb0)
}
pub const GRID_WIDTH_PT: f64 = 0.8;
pub const EDGE_WIDTH_PT: f64 = 0.8;
pub const TICK_TARGETS: usize = 11;
pub const VIEW_MARGIN: f64 = 1.0 / 48.0;
pub const AXES_LEFT: f64 = 0.191_666_666_666_666_65;
pub const AXES_BOTTOM: f64 = 0.11;
pub const AXES_WIDTH: f64 = 0.641_666_666_666_666_7;
pub const AXES_HEIGHT: f64 = 0.77;
pub const FIT_SHRINK: f64 = 0.92;
pub const DELTA_SCALE: f64 = 0.08;
pub const TICK_INWARD_FACTOR: f64 = 0.2;
pub const TICK_OUTWARD_FACTOR: f64 = 0.1;
pub const TICK_LABEL_PAD_PT: f64 = 3.5;
pub const TICK_LABEL_OFFSET_PT: f64 = 8.0;
pub const DELTAS_PER_POINT_NUM: f64 = 48.0;
}
pub mod mathtext {
pub const LARGE_OP_DISPLAY_SCALE: f32 = 1.35;
pub const LARGE_OP_TEXTSTYLE_SCALE: f32 = 1.0;
pub const LARGE_OP_LIMIT_GAP: f64 = 0.08;
pub const SCRIPT_SPACE: f64 = 0.05;
pub const SUBDROP: f64 = 0.4;
pub const SUP1: f64 = 0.7;
pub const SUB1: f64 = 0.3;
pub const SUB2: f64 = 0.5;
pub const DELTA: f64 = 0.025;
pub const DELTA_SLANTED: f64 = 0.2;
pub const DELTA_INTEGRAL: f64 = 0.1;
pub const X_HEIGHT_FRAC: f64 = 0.44;
pub const SQRT_ROOT_SHIFT: f64 = 0.6;
pub const SQRT_ROOT_KERN: f64 = 0.5;
pub const SQRT_EMPTY_ROOT_FRAC: f64 = 0.5;
pub const SQRT_BODY_CLEARANCE_THICKNESS: f64 = 5.0;
pub const SQRT_BODY_SIDE_PAD_THICKNESS: f64 = 2.0;
}
pub mod geo {
pub const MERCATOR_MAX_LAT: f64 = 85.051_128_78;
pub const COASTLINE_WIDTH_PT: f64 = 0.6;
}
pub fn chrome_expands_stock_insets(axes: &crate::axes::Axes) -> bool {
axes.needs_colorbar()
|| axes.secondary_x.is_some()
|| axes.secondary_y.is_some()
|| axes.polar
|| axes.legend.is_some_and(|l| l.is_outside())
|| axes
.title
.as_deref()
.is_some_and(crate::mathtext::needs_mathtext)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn subplot_box_matches_stock_mpl() {
assert!((subplot::AXES_WIDTH - 0.775).abs() < 1e-12);
assert!((subplot::AXES_HEIGHT - 0.77).abs() < 1e-12);
}
#[test]
fn colorbar_gutter_left_of_stock_right() {
const { assert!(colorbar::AXES_X1 < subplot::RIGHT) };
assert!((colorbar::RIGHT_GUTTER - 0.255).abs() < 1e-12);
}
#[test]
fn pie_radius_frac_is_half_view_ratio() {
assert!((pie::RADIUS_FRAC - 0.4).abs() < 1e-12);
assert!((pie::RADIUS / (2.0 * pie::VIEW) - pie::RADIUS_FRAC).abs() < 1e-12);
}
#[test]
fn polar_rmax_scales_data() {
assert!((polar::rmax_from_data(1.35) - 1.35 * 1.026).abs() < 1e-12);
}
#[test]
fn barbs_staff_matches_polycollection() {
let px = 150.0 / 72.0;
let got = barbs::staff_length_px(7.0, px);
assert!((got - 7.0 * 7.0 * 0.5 * px).abs() < 1e-12);
}
#[test]
fn twins_keep_stock_subplot_box() {
let mut ax = crate::axes::Axes::new();
assert!(!chrome_expands_stock_insets(&ax));
ax.twin_y(|t| {
t.y_label("r");
});
assert!(!chrome_expands_stock_insets(&ax));
let mut ax = crate::axes::Axes::new();
ax.twin_x(|t| {
t.x_label("top");
});
assert!(!chrome_expands_stock_insets(&ax));
}
#[test]
fn datetime_does_not_expand_via_chrome_flag() {
let mut ax = crate::axes::Axes::new();
ax.x_datetime(true);
assert!(!chrome_expands_stock_insets(&ax));
}
#[test]
fn outside_legend_expands_stock_box() {
let mut ax = crate::axes::Axes::new();
assert!(!chrome_expands_stock_insets(&ax));
ax.legend(crate::legend::Legend::OutsideUpperRight);
assert!(chrome_expands_stock_insets(&ax));
}
#[test]
fn colorbar_dense_ticks_for_small_int_span() {
assert_eq!(colorbar::linear_tick_targets(0.0, 15.0), 9);
assert_eq!(colorbar::linear_tick_targets(0.0, 9.0), 6);
assert_eq!(colorbar::linear_tick_targets(0.0, 1.0), 5);
assert_eq!(colorbar::linear_tick_targets(0.0, 100.0), 5);
assert_eq!(colorbar::linear_tick_targets(-0.9, 2.0), 7);
}
#[test]
fn violin_stem_matches_mpl_line_ends() {
assert!((violin::STEM_HALF_WIDTH_FRAC - 0.25).abs() < 1e-12);
assert_eq!(violin::POINTS, 100);
assert!((violin::WIDTHS - 0.5).abs() < 1e-12);
assert!((hexbin::POLYGON_SCALE - 1.0).abs() < 1e-12);
}
}