MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ plot_tick_labels() [1/2]

MAYAFLUX_API std::vector< LabelSpec > MayaFlux::Portal::Forma::Plot::plot_tick_labels ( const TickLabelsSpec spec)

Generate construction-free tick label specs.

Values are evenly interpolated across spec.range. Label bounds are placed adjacent to spec.plot_bounds according to spec.edge.

Definition at line 237 of file PlotSpec.cpp.

238{
239 const uint32_t count = std::max(spec.count, 2U);
240 const bool horizontal = spec.edge == TickEdge::Bottom || spec.edge == TickEdge::Top;
241
242 std::vector<LabelSpec> labels;
243 labels.reserve(count);
244
245 for (uint32_t i = 0; i < count; ++i) {
246 const float t = static_cast<float>(i) / static_cast<float>(count - 1);
247 const float value = spec.range.min + t * (spec.range.max - spec.range.min);
248 const std::string text = std::format("{:.{}f}", value,
249 static_cast<int>(spec.decimal_places));
250
251 Kinesis::AABB2D label_bounds {};
252 if (horizontal) {
253 const float cx = spec.plot_bounds.min.x + t * spec.plot_bounds.width();
254 const float half_w = spec.plot_bounds.width() / static_cast<float>(count) * 0.5F;
255
256 if (spec.edge == TickEdge::Bottom) {
257 label_bounds = Kinesis::AABB2D {
258 .min = { cx - half_w, spec.plot_bounds.min.y - spec.label_h },
259 .max = { cx + half_w, spec.plot_bounds.min.y },
260 };
261 } else {
262 label_bounds = Kinesis::AABB2D {
263 .min = { cx - half_w, spec.plot_bounds.max.y },
264 .max = { cx + half_w, spec.plot_bounds.max.y + spec.label_h },
265 };
266 }
267 } else {
268 const float cy = spec.plot_bounds.min.y + t * spec.plot_bounds.height();
269 const float half_h = spec.plot_bounds.height() / static_cast<float>(count) * 0.5F;
270
271 if (spec.edge == TickEdge::Left) {
272 label_bounds = Kinesis::AABB2D {
273 .min = { spec.plot_bounds.min.x - spec.label_w, cy - half_h },
274 .max = { spec.plot_bounds.min.x, cy + half_h },
275 };
276 } else {
277 label_bounds = Kinesis::AABB2D {
278 .min = { spec.plot_bounds.max.x, cy - half_h },
279 .max = { spec.plot_bounds.max.x + spec.label_w, cy + half_h },
280 };
281 }
282 }
283
284 labels.push_back(LabelSpec {
285 .text = text,
286 .bounds = label_bounds,
287 .color = spec.color,
288 .name = spec.name_prefix + "_" + std::to_string(i),
289 .interactive = false,
290 });
291 }
292
293 return labels;
294}
size_t count
float height() const noexcept
Definition Bounds.hpp:38
float width() const noexcept
Definition Bounds.hpp:37
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:21
float label_h
NDC height of each label strip for Bottom/Top ticks.
Definition PlotSpec.hpp:86
float label_w
NDC width of each label strip for Left/Right ticks.
Definition PlotSpec.hpp:91

References Bottom, MayaFlux::Portal::Forma::Plot::TickLabelsSpec::color, count, MayaFlux::Portal::Forma::Plot::TickLabelsSpec::count, MayaFlux::Portal::Forma::Plot::TickLabelsSpec::decimal_places, MayaFlux::Portal::Forma::Plot::TickLabelsSpec::edge, MayaFlux::Kinesis::AABB2D::height(), MayaFlux::Portal::Forma::Plot::TickLabelsSpec::label_h, MayaFlux::Portal::Forma::Plot::TickLabelsSpec::label_w, Left, MayaFlux::Kinesis::AABB2D::max, MayaFlux::Portal::Forma::Plot::AxisRange::max, MayaFlux::Kinesis::AABB2D::min, MayaFlux::Portal::Forma::Plot::AxisRange::min, MayaFlux::Portal::Forma::Plot::TickLabelsSpec::name_prefix, MayaFlux::Portal::Forma::Plot::TickLabelsSpec::plot_bounds, MayaFlux::Portal::Forma::Plot::TickLabelsSpec::range, MayaFlux::Portal::Forma::Plot::LabelSpec::text, Top, and MayaFlux::Kinesis::AABB2D::width().

Referenced by plot_tick_labels().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: