use super::funejson::Value; use super::charts_axis_axis_from_ticks::{axis_from_value, axis_line, check_orient, line_to_value}; /// One gridline per tick, from the axis line across the plot: up from a bottom /// axis, down from a top one, right from a left axis and left from a right one. /// /// # Panics /// Panics on an unknown orient or a negative or non-finite length. pub fn grid_lines(axis: &Axis, length: f64) -> Vec { check_orient(&axis.orient); if !length.is_finite() || length < 0.0 { panic!("length must be a finite number of zero or more, received {}", length); } let pos = axis.position; axis.ticks .iter() .map(|t| { let p = t.position; match axis.orient.as_str() { "bottom" => axis_line(p, pos, p, pos - length), "top" => axis_line(p, pos, p, pos + length), "left" => axis_line(pos, p, pos + length, p), _ => axis_line(pos, p, pos - length, p), } }) .collect() } pub fn fune_vector(args: &[Value]) -> Value { Value::Arr(grid_lines(&axis_from_value(&args[0]), args[1].as_f64()).iter().map(line_to_value).collect()) }