gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/plot.h
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2013年02月03日 23:23:32 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2013年02月03日 23:23:32 +0100
commite88806a5a5760aba7f5e2cd633ac3c3de2c22682 (patch)
tree2bcc9737547166674f9fb40b28b7e4aeb761e093 /agg-plot/plot.h
parenta366fbb4d0ede381163976dc46d39ab4a1e9fdba (diff)
downloadgsl-shell-e88806a5a5760aba7f5e2cd633ac3c3de2c22682.tar.gz
Factor grid drawing function in plot class
Diffstat (limited to 'agg-plot/plot.h')
-rw-r--r--agg-plot/plot.h 62
1 files changed, 31 insertions, 31 deletions
diff --git a/agg-plot/plot.h b/agg-plot/plot.h
index 49a61587..e34db2e8 100644
--- a/agg-plot/plot.h
+++ b/agg-plot/plot.h
@@ -429,6 +429,10 @@ protected:
void draw_virtual_canvas(canvas_type& canvas, plot_layout& layout, const agg::rect_i* r);
void draw_simple(canvas_type& canvas, plot_layout& layout, const agg::rect_i* r);
+ void draw_grid(const axis_e dir, const units& u,
+ const agg::trans_affine& user_mtx,
+ agg::path_storage& ln);
+
double draw_axis_m(axis_e dir, units& u, const agg::trans_affine& user_mtx,
ptr_list<draw::text>& labels, double scale,
agg::path_storage& mark, agg::path_storage& ln);
@@ -705,6 +709,31 @@ void plot<RM>::compute_user_trans()
}
template <class RM>
+void plot<RM>::draw_grid(const axis_e dir, const units& u,
+ const agg::trans_affine& user_mtx,
+ agg::path_storage& ln)
+{
+ const double eps = 1.0e-3;
+ const bool isx = (dir == x_axis);
+
+ int jinf = u.begin(), jsup = u.end();
+ for (int j = jinf+1; j < jsup; j++)
+ {
+ double uq = u.mark_value(j);
+ double x = (isx ? uq : 0), y = (isx ? 0.0 : uq);
+ user_mtx.transform(&x, &y);
+ const double q = (isx ? x : y);
+
+ if (q >= -eps && q <= 1.0 + eps)
+ {
+ ln.move_to(isx ? q : 0.0, isx ? 0.0 : q);
+ ln.line_to(isx ? q : 1.0, isx ? 1.0 : q);
+ }
+ }
+}
+
+
+template <class RM>
double plot<RM>::draw_axis_m(axis_e dir, units& u,
const agg::trans_affine& user_mtx,
ptr_list<draw::text>& labels, double scale,
@@ -755,20 +784,7 @@ double plot<RM>::draw_axis_m(axis_e dir, units& u,
mark.line_to(isx ? q : -0.01, isx ? -0.01 : q);
}
- int jinf = u.begin(), jsup = u.end();
- for (int j = jinf+1; j < jsup; j++)
- {
- double uq = u.mark_value(j);
- double x = (isx ? uq : 0), y = (isx ? 0.0 : uq);
- user_mtx.transform(&x, &y);
- double q = (isx ? x : y);
-
- if (q >= -eps && q <= 1.0 + eps)
- {
- ln.move_to(isx ? q : 0.0, isx ? 0.0 : q);
- ln.line_to(isx ? q : 1.0, isx ? 1.0 : q);
- }
- }
+ this->draw_grid(dir, u, user_mtx, ln);
double label_size;
if (bb.is_defined())
@@ -792,7 +808,6 @@ double plot<RM>::draw_xaxis_factors(units& u,
agg::path_storage& mark, agg::path_storage& ln)
{
const double text_label_size = get_default_font_size(text_axis_labels, scale);
- const double eps = 1.0e-3;
const double y_spacing = 0.05;
const unsigned layers_number = f_labels->size();
@@ -835,22 +850,7 @@ double plot<RM>::draw_xaxis_factors(units& u,
p_lab += y_spacing;
}
- // NB: IMPORTANT
- // the following code should be factored in a separate routine
- int jinf = u.begin(), jsup = u.end();
- for (int j = jinf+1; j < jsup; j++)
- {
- double uq = u.mark_value(j);
- double x = uq, y = 0.0;
- user_mtx.transform(&x, &y);
- double q = x;
-
- if (q >= -eps && q <= 1.0 + eps)
- {
- ln.move_to(q, 0.0);
- ln.line_to(q, 1.0);
- }
- }
+ this->draw_grid(x_axis, u, user_mtx, ln);
return y_spacing * layers_number;
}
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月13日 05:38:47 +0000

AltStyle によって変換されたページ (->オリジナル) /