MCPcopy Create free account
hub / github.com/alceal/plotlars / apply_mesh_axis_config

Function apply_mesh_axis_config

crates/plotlars-plotters/src/render/axis.rs:247–351  ·  view source on GitHub ↗
(
    mesh: &mut MeshStyle<'a, 'b, X, Y, DB>,
    config: &'b LayoutConfig,
    x_val_color: &'b RGBColor,
    y_val_color: &'b RGBColor,
)

Source from the content-addressed store, hash-verified

245// ── Mesh configuration shared by all chart types ───────────────────────
246
247pub(super) fn apply_mesh_axis_config<'a, 'b, X, Y, DB>(
248 mesh: &mut MeshStyle<'a, 'b, X, Y, DB>,
249 config: &'b LayoutConfig,
250 x_val_color: &'b RGBColor,
251 y_val_color: &'b RGBColor,
252) where
253 DB: DrawingBackend + 'a,
254 X: Ranged<ValueType = f64> + ValueFormatter<f64>,
255 Y: Ranged<ValueType = f64> + ValueFormatter<f64>,
256{
257 // Grid visibility
258 let x_show_grid = config.x_axis.as_ref().and_then(|a| a.show_grid);
259 let y_show_grid = config.y_axis.as_ref().and_then(|a| a.show_grid);
260
261 let x_grid_color = config.x_axis.as_ref().and_then(|a| a.grid_color.as_ref());
262 let y_grid_color = config.y_axis.as_ref().and_then(|a| a.grid_color.as_ref());
263 let x_grid_width = config.x_axis.as_ref().and_then(|a| a.grid_width);
264 let y_grid_width = config.y_axis.as_ref().and_then(|a| a.grid_width);
265
266 let has_per_axis_grid = x_grid_color.is_some() || y_grid_color.is_some();
267
268 if has_per_axis_grid {
269 // Disable built-in mesh; we draw per-axis grid lines manually after mesh.draw()
270 mesh.disable_mesh();
271 } else {
272 if x_show_grid == Some(false) && y_show_grid == Some(false) {
273 mesh.disable_mesh();
274 } else if x_show_grid == Some(false) {
275 mesh.disable_x_mesh();
276 } else if y_show_grid == Some(false) {
277 mesh.disable_y_mesh();
278 }
279
280 let grid_width = x_grid_width.or(y_grid_width);
281 if let Some(gw) = grid_width {
282 let grid_style = ShapeStyle {
283 color: RGBColor(200, 200, 200).to_rgba(),
284 filled: false,
285 stroke_width: gw as u32,
286 };
287 mesh.bold_line_style(grid_style);
288 }
289 }
290
291 // Axis visibility: show_axis(false) hides line + labels + ticks
292 let x_show_axis = config.x_axis.as_ref().and_then(|a| a.show_axis);
293 let y_show_axis = config.y_axis.as_ref().and_then(|a| a.show_axis);
294
295 if x_show_axis == Some(false) {
296 mesh.disable_x_axis();
297 }
298 if y_show_axis == Some(false) {
299 mesh.disable_y_axis();
300 }
301
302 // Axis line styling (global -- axis_style applies to both axes)
303 let x_show_line = config.x_axis.as_ref().and_then(|a| a.show_line);
304 let y_show_line = config.y_axis.as_ref().and_then(|a| a.show_line);

Callers 5

render_boxplotFunction · 0.85
render_bar_verticalFunction · 0.85
render_bar_horizontalFunction · 0.85
render_numericFunction · 0.85
render_heatmapFunction · 0.85

Calls 2

resolve_tick_sizeFunction · 0.85
colorMethod · 0.80

Tested by

no test coverage detected