From 620a1c167cbe468d6bf8adde3d45726ccc52899a Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Sat, 20 Jan 2018 13:11:17 +0300 Subject: [PATCH] OK In progress... --- src/Axis.vala | 4 +- src/Chart.vala | 4 +- src/Cursor.vala | 4 +- src/Font.vala | 110 +++++++++++++++++++--------------------- src/Grid.vala | 2 +- src/Label.vala | 40 ++++++--------- src/Legend.vala | 4 +- src/Line.vala | 120 +++++++++++++++++++++----------------------- src/Series.vala | 2 +- src/Text.vala | 24 ++++----- test/ChartTest.vala | 2 +- 11 files changed, 146 insertions(+), 170 deletions(-) diff --git a/src/Axis.vala b/src/Axis.vala index b30299d..d8fcb04 100644 --- a/src/Axis.vala +++ b/src/Axis.vala @@ -72,9 +72,9 @@ namespace CairoChart { } default = 2; } - public Font.Style font_style = Font.Style (); + public Font font_style = Font (); public Color color = Color (); - public Line.Style line_style = Line.Style (); + public LineStyle line_style = LineStyle (); public double font_spacing = 5; public virtual Axis copy () { diff --git a/src/Chart.vala b/src/Chart.vala index f4d8ca2..afc0634 100644 --- a/src/Chart.vala +++ b/src/Chart.vala @@ -81,7 +81,7 @@ namespace CairoChart { /** * Selection line style. */ - public Line.Style selection_style = Line.Style (); + public LineStyle selection_style = LineStyle (); /** * ``Chart`` cursors. @@ -303,7 +303,7 @@ namespace CairoChart { } protected virtual void rot_axes_titles () { foreach (var s in series) - s.axis_y.title.style.orientation = Font.Orientation.VERTICAL; + s.axis_y.title.style.direct = FontDirect.VERTICAL; } protected virtual void eval_plarea () { diff --git a/src/Cursor.vala b/src/Cursor.vala index 57a101c..55a9c4f 100644 --- a/src/Cursor.vala +++ b/src/Cursor.vala @@ -32,12 +32,12 @@ namespace CairoChart { public Orientation orientation; public double select_distance; - public Line.Style line_style; + public LineStyle line_style; public Style () { orientation = Orientation.VERTICAL; select_distance = 32; - line_style = Line.Style(Color(0.2, 0.2, 0.2, 0.8)); + line_style = LineStyle(Color(0.2, 0.2, 0.2, 0.8)); } } diff --git a/src/Font.vala b/src/Font.vala index e0edeb4..307ec36 100644 --- a/src/Font.vala +++ b/src/Font.vala @@ -1,78 +1,70 @@ namespace CairoChart { /** - * Text font. + * ``Font`` direction. */ - public class Font { + public enum FontDirect { /** - * ``Font`` orientation. + * Horizontal font/text direction. */ - public enum Orientation { - - /** - * Horizontal font/text orientation. - */ - HORIZONTAL = 0, - - /** - * Vertical font/text orientation. - */ - VERTICAL - } + HORIZONTAL = 0, /** - * ``Font`` Style. + * Vertical font/text direction. */ - public struct Style { + VERTICAL + } - /** - * A font family name, encoded in UTF-8. - */ - string family; + /** + * ``Font`` style. + */ + public struct Font { - /** - * The new font size, in user space units. - */ - double size; + /** + * A font family name, encoded in UTF-8. + */ + string family; - /** - * The slant for the font. - */ - Cairo.FontSlant slant; + /** + * The new font size, in user space units. + */ + double size; - /** - * The weight for the font. - */ - Cairo.FontWeight weight; + /** + * The slant for the font. + */ + Cairo.FontSlant slant; - /** - * Font/Text orientation. - */ - Orientation orientation; + /** + * The weight for the font. + */ + Cairo.FontWeight weight; - /** - * Constructs a new ``Style``. - * @param family a font family name, encoded in UTF-8. - * @param size the new font size, in user space units. - * @param slant the slant for the font. - * @param weight the weight for the font. - * @param orientation font/text orientation. - */ - public Style (string family = "Sans", - double size = 10, - Cairo.FontSlant slant = Cairo.FontSlant.NORMAL, - Cairo.FontWeight weight = Cairo.FontWeight.NORMAL, - Font.Orientation orientation = Font.Orientation.HORIZONTAL - ) { - this.family = family; - this.size = size; - this.slant = slant; - this.weight = weight; - this.orientation = orientation; - } + /** + * Font/Text direction. + */ + FontDirect direct; + + /** + * Constructs a new ``Font``. + * @param family a font family name, encoded in UTF-8. + * @param size the new font size, in user space units. + * @param slant the slant for the font. + * @param weight the weight for the font. + * @param direct font/text direction. + */ + public Font (string family = "Sans", + double size = 10, + Cairo.FontSlant slant = Cairo.FontSlant.NORMAL, + Cairo.FontWeight weight = Cairo.FontWeight.NORMAL, + FontDirect direct = FontDirect.HORIZONTAL + ) { + this.family = family; + this.size = size; + this.slant = slant; + this.weight = weight; + this.direct = direct; } - - private Font () { } } } diff --git a/src/Grid.vala b/src/Grid.vala index dfde39d..aedaf32 100644 --- a/src/Grid.vala +++ b/src/Grid.vala @@ -18,7 +18,7 @@ namespace CairoChart { /** * Line style of the ``Grid``. */ - public Line.Style line_style = Line.Style (); + public LineStyle line_style = LineStyle (); /** * Gets a copy of the ``Grid``. diff --git a/src/Label.vala b/src/Label.vala index f95cae6..3c5ef83 100644 --- a/src/Label.vala +++ b/src/Label.vala @@ -1,36 +1,28 @@ namespace CairoChart { /** - * Value of the point. + * ``LabelStyle`` Style. */ - public class Label { + public struct LabelStyle { /** - * ``Label`` Style. + * Font style. */ - public struct Style { + Font font_style; - /** - * Font style. - */ - Font.Style font_style; + /** + * Frame line style. + */ + LineStyle frame_line_style; - /** - * Frame line style. - */ - Line.Style frame_line_style; + /** + * Background color. + */ + Color bg_color; - /** - * Background color. - */ - Color bg_color; - - /** - * Frame/border color. - */ - Color frame_color; - } - - private Label () { } + /** + * Frame/border color. + */ + Color frame_color; } } diff --git a/src/Legend.vala b/src/Legend.vala index 5e5db91..6a868b1 100644 --- a/src/Legend.vala +++ b/src/Legend.vala @@ -10,9 +10,9 @@ namespace CairoChart { } public Position position = Position.TOP; - public Font.Style font_style = Font.Style(); + public Font font_style = Font(); public Color bg_color = Color(1, 1, 1); - public Line.Style border_style = Line.Style (); + public LineStyle border_style = LineStyle (); public double spacing = 5; public double width = 0; public double height = 0; diff --git a/src/Line.vala b/src/Line.vala index 3add9ad..cbd4486 100644 --- a/src/Line.vala +++ b/src/Line.vala @@ -1,80 +1,72 @@ namespace CairoChart { /** - * ``Chart`` line. + * Line Style. */ - public class Line { + public struct LineStyle { /** - * Line Style. + * Line color. */ - public struct Style { + Color color; - /** - * Line color. - */ - Color color; + /** + * A line width. + */ + double width; - /** - * A line width. - */ - double width; + /** + * An array specifying alternate lengths of on and off stroke portions. + */ + double[]? dashes; - /** - * An array specifying alternate lengths of on and off stroke portions. - */ - double[]? dashes; + /** + * An offset into the dash pattern at which the stroke should start. + */ + double dash_offset; + /** + * A line join style. + */ + Cairo.LineJoin join; - /** - * An offset into the dash pattern at which the stroke should start. - */ - double dash_offset; - /** - * A line join style. - */ - Cairo.LineJoin join; + /** + * A line cap style. + */ + Cairo.LineCap cap; - /** - * A line cap style. - */ - Cairo.LineCap cap; - - /** - * Constructs a new ``Style``. - * @param color line color. - * @param width a line width. - * @param dashes an array specifying alternate lengths of on and off stroke portions. - * @param dash_offset an offset into the dash pattern at which the stroke should start. - * @param join a line join style. - * @param cap a line cap style. - */ - public Style (Color color = Color(), - double width = 1, - double[]? dashes = null, - double dash_offset = 0, - Cairo.LineJoin join = Cairo.LineJoin.MITER, - Cairo.LineCap cap = Cairo.LineCap.ROUND - ) { - this.color = color; - this.width = width; - this.dashes = dashes; - this.dash_offset = dash_offset; - this.join = join; - this.cap = cap; - } - - /** - * Applies current style to the {@link Chart} ``Context``. - */ - public void apply (Chart chart) { - chart.color = color; - chart.ctx.set_line_width(width); - chart.ctx.set_dash(dashes, dash_offset); - chart.ctx.set_line_join(join); - chart.ctx.set_line_cap(cap); - } + /** + * Constructs a new ``LineStyle``. + * @param color line color. + * @param width a line width. + * @param dashes an array specifying alternate lengths of on and off stroke portions. + * @param dash_offset an offset into the dash pattern at which the stroke should start. + * @param join a line join style. + * @param cap a line cap style. + */ + public LineStyle (Color color = Color(), + double width = 1, + double[]? dashes = null, + double dash_offset = 0, + Cairo.LineJoin join = Cairo.LineJoin.MITER, + Cairo.LineCap cap = Cairo.LineCap.ROUND + ) { + this.color = color; + this.width = width; + this.dashes = dashes; + this.dash_offset = dash_offset; + this.join = join; + this.cap = cap; } - private Line () { } + /** + * Applies current style to the {@link Chart} ``Context``. + */ + public void apply (Chart chart) { + chart.color = color; + chart.ctx.set_line_width(width); + chart.ctx.set_dash(dashes, dash_offset); + chart.ctx.set_line_join(join); + chart.ctx.set_line_cap(cap); + } } } diff --git a/src/Series.vala b/src/Series.vala index 18c4172..1e6d7b8 100644 --- a/src/Series.vala +++ b/src/Series.vala @@ -21,7 +21,7 @@ namespace CairoChart { public Grid grid = new Grid (); - public Line.Style line_style = Line.Style (); + public LineStyle line_style = LineStyle (); protected Color _color = Color (0.0, 0.0, 0.0, 1.0); public Color color { diff --git a/src/Text.vala b/src/Text.vala index 1774001..4e1270e 100644 --- a/src/Text.vala +++ b/src/Text.vala @@ -1,7 +1,7 @@ namespace CairoChart { public class Text { public string text = ""; - public Font.Style style = Font.Style (); + public Font style = Font (); public Color color = Color(); public double vspacing = 4; public double hspacing = 4; @@ -25,18 +25,18 @@ namespace CairoChart { public virtual double get_width (Cairo.Context ctx) { var extents = get_extents (ctx); - switch (style.orientation) { - case Font.Orientation.HORIZONTAL: return extents.width; - case Font.Orientation.VERTICAL: return extents.height; + switch (style.direct) { + case FontDirect.HORIZONTAL: return extents.width; + case FontDirect.VERTICAL: return extents.height; default: return 0.0; } } public virtual double get_height (Cairo.Context ctx) { var extents = get_extents (ctx); - switch (style.orientation) { - case Font.Orientation.HORIZONTAL: return extents.height; - case Font.Orientation.VERTICAL: return extents.width; + switch (style.direct) { + case FontDirect.HORIZONTAL: return extents.height; + case FontDirect.VERTICAL: return extents.width; default: return 0.0; } } @@ -49,12 +49,12 @@ namespace CairoChart { public virtual Size get_size (Cairo.Context ctx) { var sz = Size(); var extents = get_extents (ctx); - switch (style.orientation) { - case Font.Orientation.HORIZONTAL: + switch (style.direct) { + case FontDirect.HORIZONTAL: sz.width = extents.width + extents.x_bearing; sz.height = extents.height; break; - case Font.Orientation.VERTICAL: + case FontDirect.VERTICAL: sz.width = extents.height; // + extents.x_bearing ? sz.height = extents.width; // +- extents.y_bearing ? break; @@ -67,7 +67,7 @@ namespace CairoChart { style.slant, style.weight); ctx.set_font_size(style.size); - if (style.orientation == Font.Orientation.VERTICAL) { + if (style.direct == FontDirect.VERTICAL) { ctx.rotate(- GLib.Math.PI / 2.0); ctx.show_text(text); ctx.rotate(GLib.Math.PI / 2.0); @@ -77,7 +77,7 @@ namespace CairoChart { } public Text (string text = "", - Font.Style style = Font.Style(), + Font style = Font(), Color color = Color() ) { this.text = text; diff --git a/test/ChartTest.vala b/test/ChartTest.vala index c4b442b..cb0c058 100644 --- a/test/ChartTest.vala +++ b/test/ChartTest.vala @@ -249,7 +249,7 @@ int main (string[] args) { plot_chart3 (chart3); plot_chart4 (chart4); - chart1.selection_style = Line.Style(Color(0.3, 0.3, 0.3, 0.7)); + chart1.selection_style = LineStyle(Color(0.3, 0.3, 0.3, 0.7)); var da = new DrawingArea(); da.set_events ( Gdk.EventMask.BUTTON_PRESS_MASK