MCPcopy Index your code
hub / github.com/askanium/rustplotlib / generate_ticks

Method generate_ticks

src/axis.rs:115–141  ·  view source on GitHub ↗

Generate ticks for the axis based on the scale and position.

(scale: &'a dyn Scale<T>, position: AxisPosition)

Source from the content-addressed store, hash-verified

113
114 /// Generate ticks for the axis based on the scale and position.
115 fn generate_ticks<'a, T: ToString>(scale: &'a dyn Scale<T>, position: AxisPosition) -> Vec<AxisTick> {
116 let mut ticks = Vec::new();
117 let label_offset = {
118 if position == AxisPosition::Top || position == AxisPosition::Bottom {
119 16
120 } else {
121 12
122 }
123 };
124
125 for tick in scale.get_ticks() {
126 let tick_offset = match position {
127 AxisPosition::Bottom if scale.get_type() == ScaleType::Band => scale.scale(&tick) + scale.bandwidth().unwrap() / 2_f32,
128 AxisPosition::Bottom => scale.scale(&tick),
129 AxisPosition::Left if scale.get_type() == ScaleType::Band => scale.scale(&tick) + scale.bandwidth().unwrap() / 2_f32,
130 AxisPosition::Left => scale.scale(&tick),
131 AxisPosition::Top if scale.get_type() == ScaleType::Band => scale.scale(&tick) + scale.bandwidth().unwrap() / 2_f32,
132 AxisPosition::Top => scale.scale(&tick),
133 AxisPosition::Right if scale.get_type() == ScaleType::Band => scale.scale(&tick) + scale.bandwidth().unwrap() / 2_f32,
134 AxisPosition::Right => scale.scale(&tick),
135 };
136 let axis_tick = AxisTick::new(tick_offset, label_offset, tick.to_string(), position);
137 ticks.push(axis_tick);
138 }
139
140 ticks
141 }
142
143 /// Generate the line that represents the axis.
144 fn get_axis_line<'a>(position: AxisPosition, chart: &Chart<'a>) -> AxisLine {

Callers

nothing calls this directly

Calls 4

get_ticksMethod · 0.45
get_typeMethod · 0.45
scaleMethod · 0.45
bandwidthMethod · 0.45

Tested by

no test coverage detected