diff options
author | Yordan Karadzhov (VMware) <y.karadz@gmail.com> | 2020-12-11 17:07:52 +0200 |
---|---|---|
committer | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2020-12-21 19:13:16 -0500 |
commit | df4b7308913d80af145d8725adfac5b9a61fe0ab (patch) | |
tree | b91a0e5e9d8b45d56da9c3ebd20c4d883bad98dd | |
parent | 81954c32724212e02a1e279441f019751c9a084f (diff) | |
download | kernel-shark-df4b7308913d80af145d8725adfac5b9a61fe0ab.tar.gz |
kernel-shark: Add ksplot_draw_polyline()
The method draws continuous line between an ordered array of
points (poly-line).
Link: https://lore.kernel.org/linux-trace-devel/20201211150756.577366-29-y.karadz@gmail.com
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r-- | src/libkshark-plot.c | 32 | ||||
-rw-r--r-- | src/libkshark-plot.h | 5 |
2 files changed, 31 insertions, 6 deletions
diff --git a/src/libkshark-plot.c b/src/libkshark-plot.c index c9a35305..597e5c25 100644 --- a/src/libkshark-plot.c +++ b/src/libkshark-plot.c @@ -152,6 +152,30 @@ void ksplot_draw_line(const struct ksplot_point *a, } /** + * @brief Draw the a polyline. + * + * @param points: Input location for the array of points defining the polyline. + * @param n_points: The size of the array of points. + * @param col: The color of the polyline. + * @param size: The size of the polyline. + */ +void ksplot_draw_polyline(const struct ksplot_point *points, + size_t n_points, + const struct ksplot_color *col, + float size) +{ + if (!points || !n_points || !col || size < .5f) + return; + + /* Loop over the points of the polygon and draw connecting lines. */ + for(size_t i = 1; i < n_points; ++i) + ksplot_draw_line(&points[i - 1], + &points[i], + col, + size); +} + +/** * @brief Draw a polygon. * * @param points: Input location for the array of points defining the polygon. @@ -212,12 +236,8 @@ void ksplot_draw_polygon_contour(const struct ksplot_point *points, if (!points || !n_points || !col || size < .5f) return; - /* Loop over the points of the polygon and draw connecting lines. */ - for(size_t i = 1; i < n_points; ++i) - ksplot_draw_line(&points[i - 1], - &points[i], - col, - size); + /* Loop over the points of the polygon and draw a polyline. */ + ksplot_draw_polyline(points, n_points, col, size); /* Close the contour. */ ksplot_draw_line(&points[0], diff --git a/src/libkshark-plot.h b/src/libkshark-plot.h index 063740d9..d881b20a 100644 --- a/src/libkshark-plot.h +++ b/src/libkshark-plot.h @@ -72,6 +72,11 @@ void ksplot_draw_line(const struct ksplot_point *a, const struct ksplot_color *col, float size); +void ksplot_draw_polyline(const struct ksplot_point *points, + size_t n_points, + const struct ksplot_color *col, + float size); + void ksplot_draw_polygon(const struct ksplot_point *points, size_t n_points, const struct ksplot_color *col, |