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;
}
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 () {

View File

@ -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 () {

View File

@ -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));
}
}

View File

@ -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 () { }
}
}

View File

@ -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``.

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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);
}
}
}

View File

@ -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 {

View File

@ -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;

View File

@ -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