OK In progress...

This commit is contained in:
Kolan Sh 2018-01-20 13:11:17 +03:00
parent 89132d91fc
commit 620a1c167c
11 changed files with 146 additions and 170 deletions

View File

@ -72,9 +72,9 @@ namespace CairoChart {
} }
default = 2; default = 2;
} }
public Font.Style font_style = Font.Style (); public Font font_style = Font ();
public Color color = Color (); public Color color = Color ();
public Line.Style line_style = Line.Style (); public LineStyle line_style = LineStyle ();
public double font_spacing = 5; public double font_spacing = 5;
public virtual Axis copy () { public virtual Axis copy () {

View File

@ -81,7 +81,7 @@ namespace CairoChart {
/** /**
* Selection line style. * Selection line style.
*/ */
public Line.Style selection_style = Line.Style (); public LineStyle selection_style = LineStyle ();
/** /**
* ``Chart`` cursors. * ``Chart`` cursors.
@ -303,7 +303,7 @@ namespace CairoChart {
} }
protected virtual void rot_axes_titles () { protected virtual void rot_axes_titles () {
foreach (var s in series) 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 () { protected virtual void eval_plarea () {

View File

@ -32,12 +32,12 @@ namespace CairoChart {
public Orientation orientation; public Orientation orientation;
public double select_distance; public double select_distance;
public Line.Style line_style; public LineStyle line_style;
public Style () { public Style () {
orientation = Orientation.VERTICAL; orientation = Orientation.VERTICAL;
select_distance = 32; 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));
} }
} }

View File

@ -1,78 +1,70 @@
namespace CairoChart { namespace CairoChart {
/** /**
* Text font. * ``Font`` direction.
*/ */
public class Font { public enum FontDirect {
/** /**
* ``Font`` orientation. * Horizontal font/text direction.
*/ */
public enum Orientation { HORIZONTAL = 0,
/**
* Horizontal font/text orientation.
*/
HORIZONTAL = 0,
/**
* Vertical font/text orientation.
*/
VERTICAL
}
/** /**
* ``Font`` Style. * Vertical font/text direction.
*/ */
public struct Style { VERTICAL
}
/** /**
* A font family name, encoded in UTF-8. * ``Font`` style.
*/ */
string family; public struct Font {
/** /**
* The new font size, in user space units. * A font family name, encoded in UTF-8.
*/ */
double size; string family;
/** /**
* The slant for the font. * The new font size, in user space units.
*/ */
Cairo.FontSlant slant; double size;
/** /**
* The weight for the font. * The slant for the font.
*/ */
Cairo.FontWeight weight; Cairo.FontSlant slant;
/** /**
* Font/Text orientation. * The weight for the font.
*/ */
Orientation orientation; Cairo.FontWeight weight;
/** /**
* Constructs a new ``Style``. * Font/Text direction.
* @param family a font family name, encoded in UTF-8. */
* @param size the new font size, in user space units. FontDirect direct;
* @param slant the slant for the font.
* @param weight the weight for the font. /**
* @param orientation font/text orientation. * Constructs a new ``Font``.
*/ * @param family a font family name, encoded in UTF-8.
public Style (string family = "Sans", * @param size the new font size, in user space units.
double size = 10, * @param slant the slant for the font.
Cairo.FontSlant slant = Cairo.FontSlant.NORMAL, * @param weight the weight for the font.
Cairo.FontWeight weight = Cairo.FontWeight.NORMAL, * @param direct font/text direction.
Font.Orientation orientation = Font.Orientation.HORIZONTAL */
) { public Font (string family = "Sans",
this.family = family; double size = 10,
this.size = size; Cairo.FontSlant slant = Cairo.FontSlant.NORMAL,
this.slant = slant; Cairo.FontWeight weight = Cairo.FontWeight.NORMAL,
this.weight = weight; FontDirect direct = FontDirect.HORIZONTAL
this.orientation = orientation; ) {
} this.family = family;
this.size = size;
this.slant = slant;
this.weight = weight;
this.direct = direct;
} }
private Font () { }
} }
} }

View File

@ -18,7 +18,7 @@ namespace CairoChart {
/** /**
* Line style of the ``Grid``. * Line style of the ``Grid``.
*/ */
public Line.Style line_style = Line.Style (); public LineStyle line_style = LineStyle ();
/** /**
* Gets a copy of the ``Grid``. * Gets a copy of the ``Grid``.

View File

@ -1,36 +1,28 @@
namespace CairoChart { 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. * Frame line style.
*/ */
Font.Style font_style; LineStyle frame_line_style;
/** /**
* Frame line style. * Background color.
*/ */
Line.Style frame_line_style; Color bg_color;
/** /**
* Background color. * Frame/border color.
*/ */
Color bg_color; Color frame_color;
/**
* Frame/border color.
*/
Color frame_color;
}
private Label () { }
} }
} }

View File

@ -10,9 +10,9 @@ namespace CairoChart {
} }
public Position position = Position.TOP; 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 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 spacing = 5;
public double width = 0; public double width = 0;
public double height = 0; public double height = 0;

View File

@ -1,80 +1,72 @@
namespace CairoChart { namespace CairoChart {
/** /**
* ``Chart`` line. * Line Style.
*/ */
public class Line { public struct LineStyle {
/** /**
* Line Style. * Line color.
*/ */
public struct Style { Color color;
/** /**
* Line color. * A line width.
*/ */
Color color; double width;
/** /**
* A line width. * An array specifying alternate lengths of on and off stroke portions.
*/ */
double width; double[]? dashes;
/** /**
* An array specifying alternate lengths of on and off stroke portions. * An offset into the dash pattern at which the stroke should start.
*/ */
double[]? dashes; double dash_offset;
/**
* A line join style.
*/
Cairo.LineJoin join;
/** /**
* An offset into the dash pattern at which the stroke should start. * A line cap style.
*/ */
double dash_offset; Cairo.LineCap cap;
/**
* A line join style.
*/
Cairo.LineJoin join;
/** /**
* A line cap style. * Constructs a new ``LineStyle``.
*/ * @param color line color.
Cairo.LineCap cap; * @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.
* Constructs a new ``Style``. * @param join a line join style.
* @param color line color. * @param cap a line cap style.
* @param width a line width. */
* @param dashes an array specifying alternate lengths of on and off stroke portions. public LineStyle (Color color = Color(),
* @param dash_offset an offset into the dash pattern at which the stroke should start. double width = 1,
* @param join a line join style. double[]? dashes = null,
* @param cap a line cap style. double dash_offset = 0,
*/ Cairo.LineJoin join = Cairo.LineJoin.MITER,
public Style (Color color = Color(), Cairo.LineCap cap = Cairo.LineCap.ROUND
double width = 1, ) {
double[]? dashes = null, this.color = color;
double dash_offset = 0, this.width = width;
Cairo.LineJoin join = Cairo.LineJoin.MITER, this.dashes = dashes;
Cairo.LineCap cap = Cairo.LineCap.ROUND this.dash_offset = dash_offset;
) { this.join = join;
this.color = color; this.cap = cap;
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);
}
} }
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);
}
} }
} }

View File

@ -21,7 +21,7 @@ namespace CairoChart {
public Grid grid = new Grid (); 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); protected Color _color = Color (0.0, 0.0, 0.0, 1.0);
public Color color { public Color color {

View File

@ -1,7 +1,7 @@
namespace CairoChart { namespace CairoChart {
public class Text { public class Text {
public string text = ""; public string text = "";
public Font.Style style = Font.Style (); public Font style = Font ();
public Color color = Color(); public Color color = Color();
public double vspacing = 4; public double vspacing = 4;
public double hspacing = 4; public double hspacing = 4;
@ -25,18 +25,18 @@ namespace CairoChart {
public virtual double get_width (Cairo.Context ctx) { public virtual double get_width (Cairo.Context ctx) {
var extents = get_extents (ctx); var extents = get_extents (ctx);
switch (style.orientation) { switch (style.direct) {
case Font.Orientation.HORIZONTAL: return extents.width; case FontDirect.HORIZONTAL: return extents.width;
case Font.Orientation.VERTICAL: return extents.height; case FontDirect.VERTICAL: return extents.height;
default: return 0.0; default: return 0.0;
} }
} }
public virtual double get_height (Cairo.Context ctx) { public virtual double get_height (Cairo.Context ctx) {
var extents = get_extents (ctx); var extents = get_extents (ctx);
switch (style.orientation) { switch (style.direct) {
case Font.Orientation.HORIZONTAL: return extents.height; case FontDirect.HORIZONTAL: return extents.height;
case Font.Orientation.VERTICAL: return extents.width; case FontDirect.VERTICAL: return extents.width;
default: return 0.0; default: return 0.0;
} }
} }
@ -49,12 +49,12 @@ namespace CairoChart {
public virtual Size get_size (Cairo.Context ctx) { public virtual Size get_size (Cairo.Context ctx) {
var sz = Size(); var sz = Size();
var extents = get_extents (ctx); var extents = get_extents (ctx);
switch (style.orientation) { switch (style.direct) {
case Font.Orientation.HORIZONTAL: case FontDirect.HORIZONTAL:
sz.width = extents.width + extents.x_bearing; sz.width = extents.width + extents.x_bearing;
sz.height = extents.height; sz.height = extents.height;
break; break;
case Font.Orientation.VERTICAL: case FontDirect.VERTICAL:
sz.width = extents.height; // + extents.x_bearing ? sz.width = extents.height; // + extents.x_bearing ?
sz.height = extents.width; // +- extents.y_bearing ? sz.height = extents.width; // +- extents.y_bearing ?
break; break;
@ -67,7 +67,7 @@ namespace CairoChart {
style.slant, style.slant,
style.weight); style.weight);
ctx.set_font_size(style.size); 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.rotate(- GLib.Math.PI / 2.0);
ctx.show_text(text); ctx.show_text(text);
ctx.rotate(GLib.Math.PI / 2.0); ctx.rotate(GLib.Math.PI / 2.0);
@ -77,7 +77,7 @@ namespace CairoChart {
} }
public Text (string text = "", public Text (string text = "",
Font.Style style = Font.Style(), Font style = Font(),
Color color = Color() Color color = Color()
) { ) {
this.text = text; this.text = text;

View File

@ -249,7 +249,7 @@ int main (string[] args) {
plot_chart3 (chart3); plot_chart3 (chart3);
plot_chart4 (chart4); 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(); var da = new DrawingArea();
da.set_events ( Gdk.EventMask.BUTTON_PRESS_MASK da.set_events ( Gdk.EventMask.BUTTON_PRESS_MASK