diff --git a/src/Chart.vala b/src/Chart.vala index cd0f043..0997c13 100644 --- a/src/Chart.vala +++ b/src/Chart.vala @@ -210,14 +210,6 @@ namespace CairoChart { title.show(context); } - public virtual void set_line_style (Line.Style style) { - set_source_rgba(style.color); - context.set_line_join(style.join); - context.set_line_cap(style.cap); - context.set_line_width(style.width); - context.set_dash(style.dashes, style.dash_offset); - } - public double marker_size = 8.0; public virtual void draw_marker_at_pos (Series.MarkerType marker_type, @@ -267,7 +259,7 @@ namespace CairoChart { public Line.Style selection_style = Line.Style (); public virtual void draw_selection (double x0, double y0, double x1, double y1) { - set_line_style (selection_style); + selection_style.set(this); context.rectangle (x0, y0, x1 - x0, y1 - y0); context.stroke(); } @@ -604,7 +596,7 @@ namespace CairoChart { // 6. Draw grid lines to the s.place.zoom_y_min. var line_style = s.grid.line_style; if (joint_x) line_style.color = Color(0, 0, 0, 0.5); - set_line_style(line_style); + line_style.set(this); double y = cur_y_max - max_rec_height - s.axis_x.font_indent - (s.axis_x.title.text == "" ? 0 : sz.height + s.axis_x.font_indent); context.move_to (scr_x, y); if (joint_x) @@ -632,7 +624,7 @@ namespace CairoChart { // 6. Draw grid lines to the s.place.zoom_y_max. var line_style = s.grid.line_style; if (joint_x) line_style.color = Color(0, 0, 0, 0.5); - set_line_style(line_style); + line_style.set(this); double y = cur_y_min + max_rec_height + s.axis_x.font_indent + (s.axis_x.title.text == "" ? 0 : sz.height + s.axis_x.font_indent); context.move_to (scr_x, y); if (joint_x) @@ -755,7 +747,7 @@ namespace CairoChart { // 6. Draw grid lines to the s.place.zoom_x_min. var line_style = s.grid.line_style; if (joint_y) line_style.color = Color(0, 0, 0, 0.5); - set_line_style(line_style); + line_style.set(this); double x = cur_x_min + max_rec_width + s.axis_y.font_indent + (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_indent); context.move_to (x, scr_y); if (joint_y) @@ -771,7 +763,7 @@ namespace CairoChart { // 6. Draw grid lines to the s.place.zoom_x_max. var line_style = s.grid.line_style; if (joint_y) line_style.color = Color(0, 0, 0, 0.5); - set_line_style(line_style); + line_style.set(this); double x = cur_x_max - max_rec_width - s.axis_y.font_indent - (s.axis_y.title.text == "" ? 0 : sz.width + s.axis_y.font_indent); context.move_to (x, scr_y); if (joint_y) @@ -986,7 +978,7 @@ namespace CairoChart { if (!s.zoom_show) continue; if (s.points.length == 0) continue; var points = sort_points(s, s.sort); - set_line_style(s.line_style); + s.line_style.set(this); // draw series line for (int i = 1; i < points.length; ++i) { Point c, d; @@ -1234,7 +1226,7 @@ namespace CairoChart { var low = Point(plot_x_max, plot_y_max); // low and high var high = Point(plot_x_min, plot_y_min); // points of the cursor unowned CursorCross[] ccs = cursors_crossings[cci].crossings; - set_line_style(cursor_style.line_style); + cursor_style.line_style.set(this); for (var ci = 0, max_ci = ccs.length; ci < max_ci; ++ci) { var si = ccs[ci].series_index; var s = series[si]; diff --git a/src/Legend.vala b/src/Legend.vala index 4df492e..31a9594 100644 --- a/src/Legend.vala +++ b/src/Legend.vala @@ -73,7 +73,7 @@ namespace CairoChart { chart.set_source_rgba(bg_color); chart.context.rectangle (x0, y0, width, height); chart.context.fill(); - chart.set_line_style(border_style); + border_style.set(chart); chart.context.move_to (x0, y0); chart.context.rel_line_to (width, 0); chart.context.rel_line_to (0, height); @@ -149,7 +149,7 @@ namespace CairoChart { // series line style chart.context.move_to (x, y - title_sz.height / 2); - chart.set_line_style(s.line_style); + s.line_style.set(chart); chart.context.rel_line_to (line_length, 0); chart.context.stroke(); chart.draw_marker_at_pos (s.marker_type, x + line_length / 2, y - title_sz.height / 2); diff --git a/src/Line.vala b/src/Line.vala index f74c187..1d3dddc 100644 --- a/src/Line.vala +++ b/src/Line.vala @@ -24,6 +24,14 @@ namespace CairoChart { this.dash_offset = dash_offset; this.color = color; } + + public void set (Chart chart) { + chart.set_source_rgba(color); + chart.context.set_line_join(join); + chart.context.set_line_cap(cap); + chart.context.set_line_width(width); + chart.context.set_dash(dashes, dash_offset); + } } } }